This code does not compile with GCC4.7
struct A {};
void f(A);
struct B { B(std::tuple<A>); };
void f(B);
int main() {
f(std::make_tuple(A()));
}
Because GCC derives from A to make use of the empty base class optimization. However that causes GCC to pick f(A) and complain
error:
'A'is an inaccessible base of'tuple<A>'
Is this error granted by the C++ Standard or is this simply a bug of libstdc++?
Under clause 17 Library introduction:
This is supported by 1.4 Implementation compliance [intro.compliance]:
Implementing specified semantics through inheritance is not explicitly discussed anywhere in clause 17, but it is implicitly permitted through paragraph 3 of 17.5.2.3 above:
This is how, for example, the node-based ordered associative containers can share implementation detail (including, eventually, class members) through inheritance.
Since the external behaviour of
tupleis changed between havingAas a class member and directly inheriting it, and since this change of behaviour causes the rejection of otherwise well-formed programs (as opposed to just changing thesizeofof a class), libstdc++ is in violation of the Standard.