While refactoring some C++11 code, I stumbled upon a strange thing. Namely, it seems to be impossible to define a CV-qualified (const, volatile or const volatile) base class, e.g:
struct A { int a = 0; };
struct B: A const {}; // Error here with Clang and GCC!
However, the following compiles without errors:
struct A { int a = 0; };
using AC = A const;
struct B: AC {}; // NO ERROR HERE!? Qualifiers are ignored.
int main() {
B b;
b.a = 42; // NO ERROR modifying a field of const base.
return b.a;
}
I have two questions:
- What in the C++ standards prohibits defining a CV-qualified base class, if at all?
- Why does the second example compile?
PS: Since this is a language-lawyer question, please provide references to the C++ standard.