You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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
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
structA{ int a; char b;};
intmain(){
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