Bug 89305 - CWG DR 253 is not implemented
Summary: CWG DR 253 is not implemented
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 8.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks: c++-core-issues
  Show dependency treegraph
 
Reported: 2019-02-12 12:58 UTC by Raphael Kubo da Costa
Modified: 2022-11-09 19:51 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-02-12 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Raphael Kubo da Costa 2019-02-12 12:58:15 UTC
I can see a few bugs marked as SUSPENDED related to DR 253 and how there hadn't been an official resolution at the time.

According to http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0490r0.html and http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#253 it's part of C++17 (even though MSVC and clang implement it for older versions as well).

IOW, I believe G++ should accept the following code:

struct S {
};

struct T {
  T() {}
  const S s_;
};

rather than failing with 

const.cc: In constructor ‘T::T()’:
const.cc:5:3: error: uninitialized const member in ‘const struct S’ [-fpermissive]
   T() {}
   ^
const.cc:6:11: note: ‘const S T::s_’ should be initialized
   const S s_;
           ^~
Comment 1 Jonathan Wakely 2019-02-12 15:33:57 UTC
The resolution to the DR goes a bit further than the rule GCC has been using:

A class type T is const-default-constructible if default-initialization of T would invoke a user-provided constructor of T (not inherited from a base class) or if

   - each direct non-variant non-static data member M of T has a default member initializer or, if M is of class type X (or array thereof), X is const-default-constructible,
   - if T is a union with at least one non-static data member, exactly one variant member has a default member initializer,
   - if T is a not a union, for each anonymous union member with at least one non-static data member (if any), exactly one non-static data member has a default member initializer, and
   - each potentially constructed base class of T is const-default-constructible.