[cfe-dev] static const POD object

John McCall rjmccall at apple.com
Tue Feb 19 11:57:16 PST 2013


On Feb 19, 2013, at 12:13 AM, zapadinsky <zapadinsky at gmail.com> wrote:
>> We can weaken this restriction in MS compatibility mode, but I don't
> otherwise think this is a compiler defect. 
> 
> It should be weaken in MS compatibility mode for sure. Now clang can't
> compile our sources which pass compilation on MSVC and gcc (with
> -fpermissive switch). For now I have no other option... 
> 
> And it is not a compiler defect. But why not to weaken this restriction by
> default? What harm can it cause? Clang is not a standard compliance tester.

It's bad code.  Yes, I understand that you're porting a presumably working
code base, so you see every diagnostic as pointless interference from the
compiler.  In practice, this pattern is very likely to be an error of omission:
either the initializer is missing (possible but not all that likely) or the variable
ought to be extern (so that it'll link against an initialized variable definition
in a different translation unit).

In the rare case where you really do want a global zero constant, it is quite
easy to suppress the diagnostic with an explicit initializer, e.g.:
  const foo x = foo();

John.



More information about the cfe-dev mailing list