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

[expr.prim.id.general] p2 The first note in the rule is a bit misleading #6379

Open
xmh0511 opened this issue Jul 16, 2023 · 4 comments
Open

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Jul 16, 2023

[expr.prim.id.general] p2 says:

If an id-expression E denotes a member M of an anonymous union ([class.union.anon]) U:

  • If U is a non-static data member, E refers to M as a member of the lookup context of the terminal name of E (after any transformation to a class member access expression ([class.mfct.non.static])).

[Example 1: o.x is interpreted as o.u.x, where u names the anonymous union member. — end example]

IIUC, the intent of the first bullet actually means the id-expression that would denote the member of U(conceptually designated by u.x) will be reinterpreted as o.x as if x is the member of o.

Consider this case:

struct A{
   union {
    int a;
  };
  void show(){
    int c =  this->a;  // #1
  }
};

The id-expression a denotes the member a of the anonymous union, and the terminal name of a is a, whose lookup context is just A, as per [basic.lookup.qual.general] p2. Hence, the intent of the rule may want to say a is interpreted as the member of A.

However, the note conveys a converse meaning with the intent, I think.

@jensmaurer
Copy link
Member

You didn't quote a note.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Jul 16, 2023

You didn't quote a note.

The note is

[Example 1: o.x is interpreted as o.u.x, where u names the anonymous union member. — end example]

Presumably, o means the object expression, and u.x conceptually means x is a member of u.

@jensmaurer
Copy link
Member

That's not a note, that's an example. Notes are introduced by "Note:", examples are introduced by "Example:".

@xmh0511
Copy link
Contributor Author

xmh0511 commented Jul 16, 2023

Ok, so the example is so.

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