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.mem.enum] Fix consistency of example with [temp.inst] (editorial) #7558

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

thebrandre
Copy link

The example is inconsistent with [temp.inst] p3, which states the following:

The implicit instantiation of a class template specialization causes

  • the implicit instantiation of the declarations, but not of the definitions, of [...] scoped member enumerations [...]; and
  • the implicit instantiation of the definitions of [...] unscoped member enumerations [...]

Hence, the example can be fixed by either (1) omitting the instantiation or (2) by replacing the unscoped with a scoped enumeration. Since the implicit instantiation does not contribute to the point of [temp.mem.enum], the inconsistency can be solved most easily with alternative (1).

The example was taken exactly as is from DR1206, where it already seems to be an accidental copy-paste mishap because it is not important for the statement it is trying to make.
If one is willing to assume that, it is just an editorial issue.

Note: the example as is does not compile with any of the major compilers.
See here on Compiler Explorer: https://godbolt.org/z/xjM15MjP8

The example is inconsistent with [temp.inst] p3, which states the following:
"The implicit instantiation of a class template specialization causes
 - the implicit instantiation of the declarations, but not of the definitions,
   of [...] scoped member enumerations [...]; and
 - the implicit instantiation of the definitions of [...]
   unscoped member enumerations [...]"

Hence, the example can be fixed by either (1) omitting the instantiation or
(2) by replacing the unscoped with a scoped enumeration.
Since the implicit instantiation does not contribute to the point of
[temp.mem.enum], the inconsistency can be solved most easily with alternative (1).

Note: The example was originally taken from DR1206.
Copy link
Member

@jensmaurer jensmaurer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@jensmaurer
Copy link
Member

@thebrandre, if you wish for your real name to appear in the commit history, you need to configure it in github.

@thebrandre
Copy link
Author

@jensmaurer Thanks for pointing that out! I just updated my GitHub profile.

@lprv
Copy link
Contributor

lprv commented Jan 12, 2025

This is related to CWG1485

@thebrandre
Copy link
Author

@lprv To my understanding, CWG Issue 1485 addresses an issue unrelated to templates:

struct S {
    // opaque-enum-declaration in class scope
    enum E : int;
};

// enum-specifier in namespace scope
enum S::E : int { X, Y, Z };

int x = X;           // (1) correct if enumerator declared in namespace scope?
int y = S::Y;        // (2) correct if enumerator declared in the scope of the enum-head?

This might have lead to the change from C++11 (N3242) [dcl.enum] p11

Each enum-name and each unscoped enumerator is declared in the scope that immediately contains the enum-specifier.

to C++23 (N4950) [dcl.enum] p12:

The name of each unscoped enumerator is also bound in the scope that immediately contains the enum-specifier.

Interestingly, this changed only recently from C++20 to C++23 considering it was brought up on 2012-03-26.

Hence, in the code example above, both (1) and (2) should be correct as of C++23 with (2) having much broader compiler support regardless on the choice of -std=c++11 or -std=c++23. In fact, all users, as long as they don't use Clang only, currently need to use (2), as you can see Compiler Explorer.

My proposed change should therefore not be affected.

To me, it rather seems that way that CWG Issue 1485 might have even pointed out the issue that would be fixed by this PR.


What astonishes me is the note on CWG Issue 1485:

Notes from the October, 2012 meeting:
CWG agreed that an unscoped opaque enumeration in class scope should be forbidden.

This seems like a harsh decision, which, as far as I can tell, does not seem to be reflected by the current standard documents.
Additionally, it has far more potential to break existing code.

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.

4 participants