Inherited const attribute and initialization (bug?)

attributes, c++, constants, inheritance, initialization

Solution

This is indeed a compiler bug, reported here.

Problem

I've been surprised that this code is actually considered correct (gcc 4.2.1) : ``` class A { public: const int i; }; class B: public A { public: //B() {} }; ``` so that I am able to let some attribute non initialized. The compiler complains when I try to instantiate A (I agree of course) but let me instantiate B without any warning or error! But worse, the compiler is inconsistent. When I uncomment B's empty ctor, then the compiler complains when I instantiate B... Seems like a bug to me, right or not ? Or did I've made a mistake somewhere ?

Original source