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

Richard Smith via cfe-dev cfe-dev at lists.llvm.org
Tue Jan 16 10:59:43 PST 2018


On 16 January 2018 at 10:43, Friedman, Eli via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> On 1/16/2018 4:14 AM, Gabriel Charette via cfe-dev wrote:
>
>> I would indeed expect, like Primiano, that -Wglobal-constructors would
>> only warn about *con*structors (one can decide to mitigate global
>> *de*structors another way, e.g. by invoking _exit() before end of main()).
>>
> The point of -Wglobal-constructors is to avoid code which runs at process
> startup.  Due to the way the C++ ABI works, a global destructor involves
> emitting a call to __cxa_atexit which runs at startup, so we warn.
>

Well, there are (at least) four distinct problems here:

 1) Code running at process startup (a performance problem)
 2) Code running at process termination (a performance problem)
 3) Global variables with non-constant initialization resulting in buggy
program startup (called the "initialization order fiasco" by some)
 4) Global variables with non-trivial destruction resulting in buggy
program shutdown, particularly in multithreaded code (if you have
non-trivial global dtors, multiple threads, and you call exit, you
typically have a bug)

It makes sense to request warnings about #3 without requesting the more
general warnings about #1; as such, ignoring destructors in the
-Wglobal-constructors warning would seem reasonable to me. (That allows all
four problems to be detected by some combination of the two warning flags.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180116/c7ed0048/attachment.html>


More information about the cfe-dev mailing list