This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
GCC 7 needs temporary for brace-initializing (non-literal-type) member variable?
- From: "Titus Von Boxberg" <tvb377 at gmx dot de>
- To: gcc at gcc dot gnu dot org
- Date: Fri, 6 Oct 2017 22:51:54 +0200
- Subject: GCC 7 needs temporary for brace-initializing (non-literal-type) member variable?
- Authentication-results: sourceware.org; auth=none
- Sensitivity: Normal
Hello,
this sample fails to compile with gcc 7.1 and 7.2
--------------
class A {
private:
public:
constexpr A() {}
~A() {}
};
class B {
private:
A a;
public:
constexpr B() : a{} {}
// works also with g++ -std=c++17:
// constexpr B() : a() {}
~B() {}
};
------------------
with
error: temporary of non-literal type ‘A’ in a constant expression
note: ‘A’ has a non-trivial destructor
BUT ONLY when compiled with -std=c++17
With -std=c++11 and 14 g++ accepts this code.
g++ -std=c++17 accepts the code when replacing the brace-initialization
of B::a by parentheses ()
The unmodified code also compiles fine e.g. with MS cl.exe 19.11 and clang 5.0 -std=c++1{147}
Did I overlook something?
Or should I file a bug? Or is there already one I could not find?
Thanks already for any insight!
Regards,
Titus