Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inherited const attribute and initialization (bug?)

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 ?

like image 518
Jean-Baptiste Yunès Avatar asked Jan 28 '13 14:01

Jean-Baptiste Yunès


1 Answers

This is indeed a compiler bug, reported here.

like image 65
Mike Seymour Avatar answered Nov 13 '22 06:11

Mike Seymour