Bug 80804 - Default constructor improperly invoked in C++1z mode
Summary: Default constructor improperly invoked in C++1z mode
Status: RESOLVED DUPLICATE of bug 81311
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.1.0
: P3 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
: 97277 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-05-17 13:56 UTC by Barry Revzin
Modified: 2021-08-17 07:03 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 8.1.0
Known to fail: 7.5.0
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Barry Revzin 2017-05-17 13:56:23 UTC
From StackOverflow (http://stackoverflow.com/q/44015848/2069064), this code:

#include <cstdio>
#include <initializer_list>

struct S {
  S() { std::printf("DEF "); }      // (1)
  S(std::initializer_list<int> il)  // (2)
    { std::printf("L=%zu ", il.size()); }
};

int main() {
  S x({});
}

in gcc 7.1 with -std=c++1z invokes the default constructor. In C++14 mode, it invokes the initializer_list constructor, as does clang in both modes. But the default constructor shouldn't be invoked, since {} isn't an expression so the "guaranteed elision" bullet in dcl.init shouldn't apply.
Comment 1 Andrew Pinski 2021-08-09 22:09:46 UTC
Fixed in GCC 8+.
Comment 2 Andrew Pinski 2021-08-17 07:01:42 UTC
Dup of bug 81311.

*** This bug has been marked as a duplicate of bug 81311 ***
Comment 3 Andrew Pinski 2021-08-17 07:03:06 UTC
*** Bug 97277 has been marked as a duplicate of this bug. ***