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

A definition for a class introduces a class scope rather than doing that by a declaration that is not a definition #4776

Open
xmh0511 opened this issue Jul 26, 2021 · 3 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Jul 26, 2021

[basic.scope.class#1]

Any declaration of a class or class template C introduces a class scope that includes the member-specification of the class-specifier for C (if any). For each non-friend redeclaration or specialization whose target scope is or is contained by the scope, the portion after the declarator-id, class-head-name, or enum-head-name is also included in the scope.

The declaration of a class or class template does not definitely specify that the declaration must be the definition, which could be inferred from [dcl.dcl#dcl.pre-5]

In a simple-declaration, the optional init-declarator-list can be omitted only when declaring a class ([class.pre]) or enumeration ([dcl.enum]), that is, when the decl-specifier-seq contains either a class-specifier, an elaborated-type-specifier with a class-key ([class.name]), or an enum-specifier.

That hints struct C; is also a declaration of class C, however, the declaration does not introduce a class scope. I think we should reduce the extent of "declaration" to use "definition", which means only a class-specifier can introduce the class scope.

@xmh0511 xmh0511 changed the title A definition for a class introduces a class scope rather than a declaration that is not a definition A definition for a class introduces a class scope rather than a declaration that is not a definition do that Jul 26, 2021
@xmh0511 xmh0511 changed the title A definition for a class introduces a class scope rather than a declaration that is not a definition do that A definition for a class introduces a class scope rather than a declaration that is not a definition does that Jul 26, 2021
@xmh0511 xmh0511 changed the title A definition for a class introduces a class scope rather than a declaration that is not a definition does that A definition for a class introduces a class scope rather than doing that by a declaration that is not a definition Jul 26, 2021
@xmh0511
Copy link
Contributor Author

xmh0511 commented Jul 28, 2021

@jensmaurer Could you please take a look at this issue?

@jensmaurer
Copy link
Member

jensmaurer commented Jul 29, 2021

I'm not sure there is a real bug here. What exactly goes wrong if struct C; (which declares a class C) creates a class scope which happens to contain no declarations? Note that the "if any" is a nod toward the understanding that struct C; is a class declaration (but not a definition), so this seems intentional.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Jul 30, 2021

If it were, I think the argument enforces this #4775 issue. Consider this example

template < class D >
struct B {
  D::type x;
};
struct A { using type = int; };
struct C;  //#1 if it introduced a class scope of C
struct C : A, B< C >{
};

That means from the point "P" at B<C> in the base-specifier, there is no yet a member-declaration in this scope, hence, we could say S(type, C) is empty, its base classes should continue to be searched as per [class.member.lookup#4], and the note in [class.member.lookup] also says that

[Note 2: If T is incomplete, only base classes whose base-specifier appears before P are considered. If T is an instantiated class, its base classes are not dependent. — end note]

Is the base class A considered here since its base-specifier appears before P and the class C is incomplete at this point? Which obviously conflicts with the note in [basic.scope.class].

In addition, Is that "if any" maybe just a nod toward that the class-specifier with an empty "member-specification"? I cannot figure out a normative rule that can interpret the above example except that we consider that a class scope is only introduced after the closing "{" of a class-specifier and a declaration(not a definition) of a class does not introduce the scope.

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

No branches or pull requests

2 participants