On 01/22/2015 08:39 PM, David Blaikie wrote:
On Thu, Jan 22, 2015 at 1:38 AM, Yury Gribov <[email protected]> wrote:

Hi rsmith, eli.friedman,

This patch liberalizes -Wglobal-constructors to not emit warning if
constructor is likely to be optimized away. This covers important
LinkerInitialized idiom used e.g. in libsanitizer and Chromium:
   enum LinkerInitialized { LINKER_INITIALIZED };
   class Mutex {
   public:
     inline Mutex(base::LinkerInitialized) {}
   };
   Mutex mu(LINKER_INITIALIZED);  // Will be optimized away


While this is probably a useful improvement to C++98 code, is there any
reason this code couldn't use C++11's constexpr instead? (which I think
would already not produce the warning without needing to change the
compiler)

Constexpr would work in simple cases but will fail if class includes an array (for-loops are prohibited in constexpr but all members have to be initialized).

-Y

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to