[cfe-dev] -Wglobal-constructors warns on constexpr default constructor evaluated at compile-time?

Gabriel Charette via cfe-dev cfe-dev at lists.llvm.org
Tue Jan 16 02:10:17 PST 2018


Hello Clang experts,

it seems that -Wglobal-constructors throws a warning on a global using a
constexpr default constructor on classes that don't strictly have POD
members only. Given constexpr + no params implies all members are either
POD or constexpr default constructible themselves, shouldn't Clang be able
to avoid the global constructor in all cases?

e.g.:

struct Foo {
 public:
  constexpr Foo() = default;

  std::unique_ptr<int> my_int_; --> std::unique_ptr's default constructor is
constexpr <http://en.cppreference.com/w/cpp/memory/unique_ptr/unique_ptr>
};

Foo f;  --> error: declaration requires a global destructor
[-Werror,-Wglobal-constructors]

void Init() {
  printf("%d", *f.my_int_);
}

Is this expected?

Thanks,
Gab
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180116/0be35311/attachment.html>


More information about the cfe-dev mailing list