Topic: static initializer question
Author: keith <johndoe64738@yahoo.com>
Date: Sat, 13 Feb 2010 02:40:44 CST Raw View
How come this compiles without errors in g++ 4.3.4?
struct A
{
static const float a = .5f;
};
Is some change regarding static initializers in the c++ draft standard
and g++ happens to implement it?
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@googlemail.com>
Date: Sat, 13 Feb 2010 09:39:43 CST Raw View
On 13 Feb., 09:40, keith <johndoe64...@yahoo.com> wrote:
> How come this compiles without errors in g++ 4.3.4?
>
> struct A
> {
> static const float a = .5f;
>
> };
>
> Is some change regarding static initializers in the c++ draft standard
> and g++ happens to implement it?
Indeed the upcoming C++0x standard is going to relax
the constraints on in-class initializers of static data
members. In C++0x this is only feasible for const integral
and const enumeration types with an initializer that
satisfies the requirements of an /integral-constant-expression/
(9.4.2 [class.static.data]).
In C++0x the static data member (with such an initializer)
must be of const /literal/ type, which is a new type category:
It includes all /scalar/ types (integral, floating point,
pointer,..) and class types which satisfy special constraints
(trivial copy c'tor, d'tor, copy assignment op., .., and all
members and base classes must be also literal types),
and last but least arrays of the aforementioned types.
This explains, why your const float type is accepted.
Also, the restrictions for the initializer-expression will
be relaxed. According to the current state of the working
draft this must be a /constant expression/, which again
is a super-set of an integral-constant-expression (5.19
[expr.const]). For details see
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n3000.pdf
HTH & Greetings from Bremen,
Daniel Kr gler
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]