[cfe-dev] -Wglobal-constructors warns on constexpr default constructor evaluated at compile-time?
Primiano Tucci via cfe-dev
cfe-dev at lists.llvm.org
Tue Jan 16 03:09:07 PST 2018
Just in case somebody missed that, note that despite the switch name the
error message is about the **de**structor.
Which makes sense for a unique_ptr which can be constexpr constructible but
is clearly not trivially destructible. I just would have expected that to
show up in -Wexit-time-destructors not in -Wglobal-constructors.
By glancing at the code in Sema::FinalizeVarWithDestructor
<https://clang.llvm.org/doxygen/SemaDeclCXX_8cpp_source.html#12516> it
seems the logic for finalizers is:
- always warn on -Wexit-time-destructors for any sort of non trivial dtor
- warn also on -Wglobal-constructors but only for non-static-local cases.
I can't see a case that would generate a warn_exit_time_destructor without
a warn_global_destructor.
What is the intended semantic of -Wglobal-constructors? Would it be
possible to make it only warn about constructors and leave destructors only
to -Wexit-time-destructors?
On Tue, Jan 16, 2018 at 10:10 AM Gabriel Charette <gab at chromium.org> wrote:
> 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/ed2bf84b/attachment.html>
More information about the cfe-dev
mailing list