https://llvm.org/bugs/show_bug.cgi?id=25736
Bug ID: 25736 Summary: constexpr allows uninitialized variables Product: clang Version: 3.7 Hardware: PC OS: Linux Status: NEW Severity: normal Priority: P Component: C++14 Assignee: unassignedclangb...@nondot.org Reporter: tomilovanato...@gmail.com CC: llvm-bugs@lists.llvm.org Classification: Unclassified Given a code: #include <type_traits> struct A { int i; }; template< typename type > struct C { constexpr C() = default; type a; }; struct V { V() = default; C< A > d; }; constexpr bool test() { V v; static_assert(std::is_trivially_default_constructible< V >::value, "!"); return (v.d.a.i == 0); } static_assert(test(), "!"); It compiles without errors by `clang`. Compilation by `g++` failed with error: main.cpp: In function 'constexpr bool test()': main.cpp:12:11: error: uninitialized variable 'v' in 'constexpr' function V v; ^ main.cpp:8:12: note: 'struct V' has no user-provided default constructor struct V { V() = default; C< A > d; }; ^ main.cpp:8:16: note: constructor is not user-provided because it is explicitly defaulted in the class body struct V { V() = default; C< A > d; }; ^ main.cpp:3:20: note: and the implicitly-defined constructor does not initialize 'int A::i' struct A { int i; }; ^ main.cpp: At global scope: main.cpp:17:5: error: non-constant condition for static assertion static_assert(test(), "!"); ^ main.cpp:17:23: error: 'constexpr bool test()' called in a constant expression static_assert(test(), "!"); ^ If I remove `template`s and substitute `A` directly, then `clang` sees uninitialized during default construction variables. If I remove `constexpr` specifier of `C::C()` default constructor, then `clang` also sees wrong things. -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs