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

David Blaikie dblaikie at gmail.com
Fri Jan 23 00:03:56 PST 2015


On Thu, Jan 22, 2015 at 10:43 PM, Yury Gribov <y.gribov at samsung.com> wrote:

> 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).


Got an example of this? I'd imagine an in-class initializer might suffice
for the array. ( int x[3] = {}; ) ?


>
>
> -Y
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150123/3e1da12b/attachment.html>


More information about the cfe-commits mailing list