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

using-declaration is not a member vs [class.member.lookup] #4731

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

using-declaration is not a member vs [class.member.lookup] #4731

xmh0511 opened this issue Jul 3, 2021 · 4 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Jul 3, 2021

The lookup set for N in C, called S(N,C), consists of two component sets: the declaration set, a set of members named N; and the subobject set, a set of subobjects where declarations of these members were found (possibly via using-declarations).

Although the using-declaration declares a synonymous name for the declarations nominated by it, however, the using-declaration does not declare a member, hence the synonymous name is not the name of a member(i.e, a using-declaration that is found is not a declaration of a member).

A member-declaration does not declare new members of the class if it is

  • a using-declaration ([namespace.udecl]), or

For any other member-declaration, each declared entity that is not an unnamed bit-field is a member of the class, and each such member-declaration shall either declare at least one member name of the class or declare at least one unnamed bit-field.

struct A{
    int a;
};
struct B{
    char a;
};
struct C:A,B{
    using A::a;
};
C c;
c.a = 0;

Is the set of subobjects of S(a,C) {C} or{A}? There are some contradictions here.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Apr 7, 2022

@jensmaurer @opensdh

enum E {e};
struct X {
  using E::e;
};
int f(X x) {return x.e;}

The declaration set of the lookup for the member-qualified name e in scope X is {E::e} where E::e is not a member of X. I also think the subconscious intent of defining the subobject set, in this case, should be { X } where the using-declaration was found in X. So, I think the wording might be changed to

The lookup set for N in C, called S(N,C), consists of two component sets: the declaration set, a set of declarations that introduces the name N; and the subobject set, a set of subobjects where declarations that introduce N were found(possible using-declarations).

@jensmaurer
Copy link
Member

jensmaurer commented Apr 7, 2022

@opensdh, the suggested approach in the fix sounds reasonable. What do you think?

@opensdh
Copy link
Contributor

opensdh commented Apr 8, 2022

Sure. It's a very minor point—we don't say or care what they're members of—but the using of an enumerator definitely stretches it. I'd simplify by saying "… where such declarations were found (…).".

@xmh0511
Copy link
Contributor Author

xmh0511 commented Apr 8, 2022

I'd simplify by saying "… where such declarations were found (…).".

I have to say the declarations in the declaration set are not necessary to be the declarations that were found. As the above example exposed, the found declaration is the using-declaration but the recorded declaration in the declaration set is the replacing declaration for the using-declaration.

In normal cases, the declarations in the declaration set are exact the declarations that were found by lookup. However, using-declaration is special here, since it has a special specification:

If any such declaration is a using-declarator whose terminal name ([expr.prim.id.unqual]) is not dependent ([temp.dep.type]), it is replaced by the declarations named by the using-declarator ([namespace.udecl]).

Because of the replacement, they are not the same declarations.

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

3 participants