https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118276

--- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> ---
N.B. your first godbolt example never tests -DMODE=1 because the second pane
uses -DDEFAULTED=1


(In reply to Ben FrantzDale from comment #0)
> I think (?) `S() noexcept {}` is semantically the same as `S() = default;`

No, it isn't. The presence of a user-provided default constructor has semantic
effects, see [dcl.init.general]:

To value-initialize an object of type T means:
(9.1) — If T is a (possibly cv-qualified) class type (Clause 11), then let C be
the constructor selected to default-initialize the object, if any. If C is not
user-provided, the object is first zero-initialized. In all cases, the object
is then default-initialized.


Your first godbolt link does `return S{};` which means different things for
aggregates vs non-aggregates with/without user-provided constructors. For a
non-aggregate with no user-provided default ctor, the compiler is required to
zero-init the entire class, including padding bits.

Reply via email to