Unhelpful error
Dan Oram
oramd@cs.man.ac.uk
Wed Mar 24 13:54:00 GMT 1999
Hullo,
I have a somewhat minor little quible with the latest version of egcs
(1.1.2 release). It has to do with a rather unhelpful error message
sprouting from the following sort of code:
#include <vector.h>
template <unsigned int N>
class Test {
public:
int get(void) { return N; } // Line 7
};
template <unsigned int n> // This is the real error, n should be N
int GetTest(Test<N> T) {
return T.get();
}
int main() {
Test<2> T;
cerr << GetTest(T) << endl; // Line 16
}
When passed to the compiler with the mistake of n instead of N (see the
comments in the above code), this error message is given:
bash$ g++ Test.cc -o Test
Test.cc: In function `int main()':
Test.cc:16: `N' undeclared (first use this function)
Test.cc:16: (Each undeclared identifier is reported only once
Test.cc:16: for each function it appears in.)
Test.cc:16: sorry, not implemented: use of `error_mark' in template type
unification
Test.cc:16: no matching function for call to `GetTest (Test<2> &)'
As you can easily see, the error is flagged at the invocation of GetTest,
without any mention of the faulty GetTest function. Naturaly if the above
code was split up over different files it could be hard to track down (I had
a similar problem in an operator< which took some tracking down because the
error was getting thrown in the Standard C++ library on < for a dereferenced
iterator). I suppose at line 16 it should throw an invoked from here error
as it would if a similar thing was done within a class (e.g. making the same
error of exchanging n for N at line 7 and invoking the get method):
bash$ g++ Test.cc -o Test
Test.cc: In method `int Test<2>::get<2>()':
Test.cc:16: instantiated from here
Test.cc:6: `N' undeclared (first use this function)
Test.cc:6: (Each undeclared identifier is reported only once
Test.cc:6: for each function it appears in.)
Hope that helps,
Dan.
More information about the Gcc-bugs
mailing list