The error message for the ill-formed code below is hard to read because of
the unnecessary cast and the explicit qualification of the data member. The
error becomes essentially unreadable when the code is more involved. Other
compilers manage to do better. For example, here's the diagnostic issued
for the same file by EDG eccp:
"t.cpp", line 5: error: no operator "+=" matches these operands
operand types are: A<int> += const A<int>
a [0] += x;
^
detected during instantiation of
"void B<T>::operator=(const A<T> &) [with T=int]" at line
15
1 error detected in the compilation of "t.cpp".
$ cat t.cpp && gcc t.cpp
template <class> struct A { };
template <class T> struct B {
void operator= (const A<T> &x) {
a [0] += x;
}
A<T> *a;
};
int main ()
{
A<int> a;
B<int> b;
b = a;
}
t.cpp: In member function 'void B<T>::operator=(const A<T>&) [with T = int]':
t.cpp:15: instantiated from here
t.cpp:5: error: no match for 'operator+=' in '*((B<int>*)this)->B<int>::a += x'
--
Summary: cryptic expression in error message for ill-formed
template code
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: sebor at roguewave dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30378