<div dir="ltr">Just in case somebody missed that, note that despite the switch name the error message is about the **de**structor.<div>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.</div><div><br></div><div>By glancing at the code in <a href="https://clang.llvm.org/doxygen/SemaDeclCXX_8cpp_source.html#12516">Sema::FinalizeVarWithDestructor</a> it seems the logic for finalizers is:</div><div>- always warn on -Wexit-time-destructors for any sort of non trivial dtor</div><div>- warn also on -Wglobal-constructors but only for non-static-local cases.</div><div><br></div><div>I can't see a case that would generate a warn_exit_time_destructor without a warn_global_destructor.</div><div>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?<br><br><div class="gmail_quote"><div dir="ltr">On Tue, Jan 16, 2018 at 10:10 AM Gabriel Charette <<a href="mailto:gab@chromium.org">gab@chromium.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello Clang experts,<div><br></div><div>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?</div><div><br></div><div>e.g.:</div><div><br></div><div><div><font face="monospace">struct Foo {</font></div><div><font face="monospace"> public:</font></div><div><font face="monospace">  constexpr Foo() = default;</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">  std::unique_ptr<int> my_int_; --> std::unique_ptr's default constructor <a href="http://en.cppreference.com/w/cpp/memory/unique_ptr/unique_ptr" class="m_5856015828317031981cremed" target="_blank">is constexpr</a></font></div><div><font face="monospace">};</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">Foo f;  --> error: declaration requires a global destructor [-Werror,-Wglobal-constructors]</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">void Init() {</font></div><div><font face="monospace">  printf("%d", *f.my_int_);</font></div><div><font face="monospace">}</font></div></div><div><br></div><div>Is this expected?</div><div><br></div><div>Thanks,</div><div>Gab</div></div>
</blockquote></div></div></div>