Skip to content

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

@xmh0511

Description

@xmh0511

[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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions