Skip to content

[basic.life] p7 A glvalue and a pointer referring/pointing to an ended lifetime object are defined different when accessing a non-static data member #582

@xmh0511

Description

@xmh0511

Full name of submitter (unless configured in github; will be published with the issue): Jim X

[basic.life] p6 says:

The program has undefined behavior if :

  • [...]
  • the pointer is used to access a non-static data member or call a non-static member function of the object, or

However, [basic.life] p7 says:

Similarly, ... The program has undefined behavior if

  • the glvalue is used to access the object, or
  • the glvalue is used to call a non-static member function of the object, or
struct A{ int a; char b;};
int main(){
   A* ptr = new A{0,1};
   ptr->~A();
   ptr->a; // undefined 
   (*ptr).a; // ??
}

As said in [basic.life] p7, the behavior of a glvalue should be defined similarly to a pointer in this aspect, however, [basic.life] p7 does not cover when accessing a non-static data member. "the object" in the first bullet presumably means the object the glvalue refers to.

Suggested Resolution

  • the glvalue is used to access the object or subobjects thereof, or

or

  • the glvalue is used to access a non-static data member or call a non-static member function of the object, or

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