What is the purpose of a default member initializer to be considered a complete-class context?

1,439 views
Skip to first unread message

Belloc

unread,
Mar 6, 2019, 9:21:11 AM3/6/19
to ISO C++ Standard - Discussion
This seems to be a defect in the Standard, as every time a code exercises its right to use the fact that a default member initializer is a complete-class context, as stated in [class.mem]/(6.5), it will end up showing undefined behavior, according to this answer in Stackoverflow. That is, when a default member initializer tries to access another member down the class member-specififcation, the code will show undefined behavior, as the accessed member is uninitialized at that point in time. 

Christof Meerwald

unread,
Mar 6, 2019, 9:52:06 AM3/6/19
to std-dis...@isocpp.org
On Wed, Mar 06, 2019 at 06:21:11AM -0800, Belloc wrote:
> This seems to be a defect in the Standard, as every time a code exercises
> its right to use the fact that a default member initializer is a
> complete-class context, as stated in [class.mem]/(6.5)
> <http://eel.is/c++draft/class.mem#6.5>, it will end up showing undefined
> behavior, according to this answer
> <https://stackoverflow.com/a/55009966/1162978> in Stackoverflow.

You mainly need the complete-class context to allow name lookup in the
complete class, e.g.

struct A
{
int i = val;
static const int val = 1;
};


> That is,
> when a default member initializer tries to access another member down the
> class *member-specififcation
> <http://eel.is/c++draft/class.mem#nt:member-specification>*, the code will
> show undefined behavior, as the accessed member is uninitialized at that
> point in time.

which is a different problem.


Christof

--

http://cmeerw.org sip:cmeerw at cmeerw.org
mailto:cmeerw at cmeerw.org xmpp:cmeerw at cmeerw.org

Chris Hallock

unread,
Mar 6, 2019, 10:40:20 AM3/6/19
to ISO C++ Standard - Discussion
On Wednesday, March 6, 2019 at 9:21:11 AM UTC-5, Belloc wrote:
This seems to be a defect in the Standard, as every time a code exercises its right to use the fact that a default member initializer is a complete-class context, as stated in [class.mem]/(6.5), it will end up showing undefined behavior, according to this answer in Stackoverflow. That is, when a default member initializer tries to access another member down the class member-specififcation, the code will show undefined behavior, as the accessed member is uninitialized at that point in time. 

I think you might be getting confused by the word "complete". Classes are "regarded as complete" (shorthand for "regarded as being a complete object type"), not initialized, in complete-class contexts. A complete-class context is a lexical region, not a point in time at runtime.

Belloc

unread,
Mar 6, 2019, 2:32:33 PM3/6/19
to ISO C++ Standard - Discussion, cme...@cmeerw.org


On Wednesday, March 6, 2019 at 11:52:06 AM UTC-3, Christof Meerwald wrote:

You mainly need the complete-class context to allow name lookup in the
complete class, e.g.

struct A
{
  int i = val;
  static const int val = 1;
};


So, what you're saying is that a default-member initializer of a non-static data member is a complete-context of its class, just to allow it to refer to a static data member of the class, which then may be located down the class member-specification. That makes sense. I haven't thought about this possibility.
Reply all
Reply to author
Forward
0 new messages