http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48980
Summary: Misleading error message when a conversion is invalid
while calling a protected base constructor
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: trivial
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
Provided with this code:
class base {
protected:
base( int * ) {}
};
struct derived : base {
derived( const int * p ) : base( p ) {}
};
The compiler correctly detects that there is an error as using p as argument to
the constructor of base will break const-correctness. The error report
identifies that condition, but it also adds a misleading first error:
error.cpp: In constructor ‘derived::derived(const int*)’:
error.cpp:5: error: ‘base::base(int*)’ is protected
error.cpp:10: error: within this context
error.cpp:10: error: invalid conversion from ‘const int*’ to ‘int*’
error.cpp:10: error: initializing argument 1 of ‘base::base(int*)’
Clearly base::base(int*) is protected, but it is accessible from the context of
the constructor derived::derived(const int*), and the first 3 lines should not
be part of the error message.
This can be reproduced with the default g++ in ubuntu/linaro, and also with g++
4.0.3 (I don't know the exact compiler flags used, but I believe the error to
be independent of compiler flags, if it is not, I can find out the exact flags
used).
g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5