[PATCH] SemaDeclCXX.cpp: Make -Wglobal-constructors more forgiving.

Yury Gribov y.gribov at samsung.com
Thu Jan 22 22:43:45 PST 2015


On 01/22/2015 08:39 PM, David Blaikie wrote:
> On Thu, Jan 22, 2015 at 1:38 AM, Yury Gribov <tetra2005 at gmail.com> 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




More information about the cfe-commits mailing list