This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GCC 7 needs temporary for brace-initializing (non-literal-type) member variable?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]