For the following case: // line 1 class A {}; class B : private A { }; extern B b; void f( A & = b); // ERROR A & a = b; // ERROR ... g++ issues only one error: t.cpp:9: error: 'A' is an inaccessible base of 'B' ... but it should also complain about the default arg. Incidentally, this example was boiled down from code in a real project.
We just don't error until you use the function, in that the following errors: // line 1 class A {}; class B : private A { }; extern B b; int f( A & = b); // ERROR A & a = b; // ERROR int x = f(); // ERROR
Ok, here's something that's a little closer to the original example: class A; class B; extern B b; struct C { static int f( A& = b); // ERROR }; class A{}; class B : public A {}; int n = C::f(); Failing to report this error doesn't appear to lead to a "real" bug, but it's still ill-formed, so when you try to port your code to a compiler with the EDG front end, you'll get: error: a reference of type "A &" (not const-qualified) cannot be initialized with a value of type "B" static int f( A& = b); // ERROR ^
(In reply to comment #2) > Ok, here's something that's a little closer to the original example: I get an error with that example: t.cc:8: error: default argument for parameter of type ‘A&’ has type ‘B’ In fact the following is valid code which is why we cannot error until you actually call f: // line 1 class A {}; class B : private A { friend void g(void);}; extern B b; void f( A & = b); // ERROR void g(void) { f(); }
Reopening for a second.
Actually I take back comment #3. This code is invalid as it violates 8.3.6/5: "The names in the expressions are bound, and the semantics constraints are checked, at the point where the default argument expression appears.
Confirmed, not a regression.
Fixed in GCC 4.8.0 by r0-118020. g++.dg/overload/defarg6.C is similar but not exactly the same.