Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[temp.pre] Fix note about uniqueness of a template name in a scope #7284

Merged
merged 1 commit into from
Nov 20, 2024

Conversation

Endilll
Copy link
Contributor

@Endilll Endilll commented Oct 3, 2024

https://eel.is/c++draft/temp.pre#7 was normative wording that was converted into a note by P1787R6. The first half of it reads:

A template cannot have the same name as any other name bound in the same scope ([basic.scope.scope]), except that a function template can share a name with non-template functions ([dcl.fct]) and/or function templates ([temp.over]).

I think it refers to wording about which declarations correspond (and consequently might conflict, rendering the program ill-formed), but it only reflects [basic.scope.scope]/4.3. The problem is that it's worded in a way that claims completeness, despite omitting 4.1 (using-declarators) and 4.2 (types not conflicting with non-types, including function templates).

This PR makes the note complete, and adds an example that focuses on function templates.

@Endilll
Copy link
Contributor Author

Endilll commented Oct 3, 2024

There appears to be no implementation divergence on the example between 4 compilers: https://godbolt.org/z/axe9j9eTr

@Endilll
Copy link
Contributor Author

Endilll commented Oct 3, 2024

Sorry, I don't understand the CI error about comments not being aligned. They seem aligned to me, even in the error message.

@erichkeane
Copy link

Sorry, I don't understand the CI error about comments not being aligned. They seem aligned to me, even in the error message.

See: # Comment not aligned to multiple of four. (Ignore lines with "@".) here:
https://github.com/cplusplus/draft/blob/main/tools/check-source.sh#L166

Diagnostic could be WAY better there.

@Endilll
Copy link
Contributor Author

Endilll commented Oct 3, 2024

Diagnostic could be WAY better there.

Opened #7285

@jensmaurer jensmaurer added the changes requested Changes to the wording or approach have been requested and not yet applied. label Oct 8, 2024
@jensmaurer
Copy link
Member

... and please squash all commits and force-push.

@Endilll Endilll force-pushed the fix-temp-pre-note branch from a11dce4 to aeb1e95 Compare October 8, 2024 11:30
@Endilll
Copy link
Contributor Author

Endilll commented Oct 8, 2024

Should be good to go now.

@Endilll Endilll force-pushed the fix-temp-pre-note branch from aeb1e95 to 91b5ed4 Compare October 8, 2024 11:35
Endilll added a commit to llvm/llvm-project that referenced this pull request Oct 8, 2024
…clared in the same scope?" (#111446)

[P1787R6](https://wg21.link/p1787r6):
> [CWG110](https://cplusplus.github.io/CWG/issues/110.html) is resolved
by reducing the restriction in [temp.pre] to a note (matching the
behavior of GCC, Clang, and ICC).

Wording: see changes to [temp.pre]/7

I believe the wording for the questions raised in the issue is now the
definition of corresponding declarations that is given in
[[basic.scope.scope]/4](https://eel.is/c++draft/basic.scope#scope-4):
> Two declarations correspond if they (re)introduce the same name, both
declare constructors, or both declare destructors, unless
> — either is a using-declarator, or
> — one declares a type (not a typedef-name) and the other declares a
variable, non-static data member other than of an anonymous union
([class.union.anon]), enumerator, function, or function template, or
> — each declares a function or function template and they do not
declare corresponding overloads.

Then it's used as an input for the definition of potentially conflicting
declarations given in
[[basic.scope.scope]/6](https://eel.is/c++draft/basic.scope#scope-6).

Answering the question in the title: yes, having a function template and
a type with the same name that has the same target scope is well-formed.

A keen eye might spot that the current
[[temp.pre]/7](https://eel.is/c++draft/temp.pre#7) note doesn't reflect
all of the exceptions from the definition of corresponding declarations
in [basic.scope.scope]/4, namely 4.1 and 4.2. I believe the note is
defective, and I opened an editorial PR against the draft to fix that:
cplusplus/draft#7284.
@Endilll
Copy link
Contributor Author

Endilll commented Oct 24, 2024

@jensmaurer Do you want me to do any further changes?

@jensmaurer jensmaurer removed the changes requested Changes to the wording or approach have been requested and not yet applied. label Oct 27, 2024
@tkoeppe tkoeppe merged commit 2cd11c5 into cplusplus:main Nov 20, 2024
2 checks passed
@Endilll Endilll deleted the fix-temp-pre-note branch November 20, 2024 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants