On 01/23/2015 11:03 AM, David Blaikie wrote:
On Thu, Jan 22, 2015 at 10:43 PM, Yury Gribov <[email protected]> wrote:
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).
Got an example of this? I'd imagine an in-class initializer might suffice
for the array. ( int x[3] = {}; ) ?
Yup, this seems to do the trick. I guess the patch is thus not that
important.
-Y
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits