On Fri, May 31, 2019 at 11:50:47AM -0400, Marek Polacek wrote: > On Thu, May 30, 2019 at 05:28:47PM -0600, Martin Sebor wrote: > > On 5/28/19 3:30 PM, Sean Gillespie wrote: > > > This adds a new warning, -Wglobal-constructors, that warns whenever a > > > decl requires a global constructor or destructor. This new warning fires > > > whenever a thread_local or global variable is declared whose type has a > > > non-trivial constructor or destructor. When faced with both a constructor > > > and a destructor, the error message mentions the destructor and is only > > > fired once. > > > > > > This warning mirrors the Clang option -Wglobal-constructors, which warns > > > on the same thing. -Wglobal-constructors was present in Apple's GCC and > > > later made its way into Clang. > > > > > > Bootstrapped and regression-tested on x86-64 linux, new tests passing. > > > > I can't tell from the Clang online manual: > > > > Is the warning meant to trigger just for globals, or for all > > objects with static storage duration regardless of scope (i.e., > > including namespace-scope objects and static locals and static > > class members)? > > > > "Requires a constructor to initialize" doesn't seem very clear > > to me. Is the warning intended to trigger for objects that > > require dynamic initialization? If so, then what about dynamic > > intialization of objects of trivial types, such as this: > > > > static int i = std::string ("foo").length (); > > > > or even > > > > static int j = strlen (getenv ("TMP")); > > The warning is not meant to diagnose these. But I do agree that the > documentation for the new warning should be improved.
I was partially wrong: if i/j are at file scope, then the warning triggers. But if i/j are in a function, then it doesn't warn. My apologies. Marek