[cfe-dev] static const POD object
zapadinsky
zapadinsky at gmail.com
Mon Feb 18 02:47:47 PST 2013
MSVC allows static const objects.
In MSVC this code:
struct A {
int v;
};
static const a;
will compiles and a.v will be zero. But clang and gcc issue errors:
error: default initialization of an object of const type 'const struct A'
requires a user-provided default constructor
error: uninitialized const ‘a’ [-fpermissive]
There was resolved issue here:
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#78 , now
standard states:
[2003: 8.5/6]: Every object of static storage duration shall be
zero-initialized at program startup before any other initialization takes
place.
[2003: 8.5/9]: If no initializer is specified for an object, and the object
is of (possibly cv-qualified) non-POD class type (or array thereof), the
object shall be default-initialized; if the object is of const-qualified
type, the underlying class type shall have a user-declared default
constructor. Otherwise, if no initializer is specified for a nonstatic
object, the object and its subobjects, if any, have an indeterminate initial
value; if the object or any of its subobjects are of const-qualified type,
the program is ill-formed.
Looks like Judy Ward suggestion was misunderstood.
It's perfectly fine to instantiate a const static object according to this
paragraphs. And this object should be zero-initialized constant object.
--
View this message in context: http://clang-developers.42468.n3.nabble.com/static-const-POD-object-tp4030470.html
Sent from the Clang Developers mailing list archive at Nabble.com.
More information about the cfe-dev
mailing list