llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

constexpr static data member without initializer

Open KarstenH opened this issue 8 years ago • 1 comments

Bugzilla Link 35852
Resolution INVALID
Resolved on Jun 01, 2018 07:08
Version trunk
OS Windows XP

Extended Description

#include

struct S { static std::complex constexpr c; };

The compiler does not generate an error although an initializer is missing. As far as I know a constexpr static data member must have an initializer, even if it is of class type that has a constructor that can be called without arguments (as in this case). The correct code should initialize with a constructor, for instance:

struct S { static std::complex constexpr c {}; };

As a side note: clang <= 3.8.1 and gcc (all versions) do not compile this code and report the missing initializer.

Now who's right and who's wrong?

KarstenH avatar Jan 07 '18 23:01 KarstenH

In C++17 mode it seems clang is right and gcc is wrong: https://stackoverflow.com/questions/50638053/constexpr-static-data-member-without-initializer As a result I close this issue.

KarstenH avatar Jun 01 '18 14:06 KarstenH