https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66450
Bug ID: 66450 Summary: [5 Regression][C++11][constexpr] Issues when delegating implicit copy constructor in constexpr function Product: gcc Version: 5.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mosra at centrum dot cz Target Milestone: --- The following code is compiled fine in both GCC 4.9.2 and Clang 3.6: struct foo { constexpr foo(int a); constexpr foo(int a, int b, int c): a{a}, b{b}, c{c} {} int a, b, c; }; constexpr foo make_foo(int a) { return foo{a, a+1, a+2}; } constexpr foo::foo(int a): foo{make_foo(a)} {} int main() { constexpr const foo f{3}; static_assert(f.a == 3, ""); static_assert(f.b == 4, ""); static_assert(f.c == 5, ""); } In GCC 5.1 it produces an error about non-constant condition for static assertion. If the relevant lines are changed to runtime assert (and #include <cassert> added): assert(f.a == 3); assert(f.b == 4); assert(f.c == 5); Then all three assertions fail at runtime, because the copy constructor is somehow not called and the structure is instead just zeroed out. HOWEVER, if you remove all occurrences of the constexpr keyword, the code compiles, no runtime assertion is fired and everything behaves as expected. The behavior is the same for -std=c++11 and -std=c++14. I think the static assertion error and the zero-initialization are somehow related, so I put these into single issue instead of creating two separate ones.