Wrong name in error messages (egcs-19990907)
Jeroen
Jeroen
Tue Sep 14 02:29:00 GMT 1999
Hi, here are some more oddities with gcc when it encounters an error :
template <typename T>
class A
{
public:
#ifdef F1
A() {}
#endif
};
template <typename T>
class B
{
public:
template <class C> void f(int p, C& c)
{
f(p,c);
}
void f(int p)
{
A<T> c;
f(p,c); // this works
#if F2 == 1
f(p, A<T>()); // line 25: doesn't work
#endif
#if F2 == 2
f(p, (A<T>())); // line 28:workaround as suggested in FAQ (Parse
Errors for simple code)
#endif
#if F2 == 3
f(p, (0, A<T>())); // line 31:other workaround as suggested in FAQ
(Parse Errors for simple code)
#endif
}
};
void f1()
{
B<char> c;
c.f(1);
}
// g++ -v
// Reading specs from
/hdc1/home2/egcs/experimental/lib/gcc-lib/i686-pc-linux-gnu/2.96/specs
// gcc version 2.96 19990907 (experimental)
// 1. no problem
// -------------
// g++ -W -Wall -c g.cpp
// g++ -W -Wall -c g.cpp -DF1
// 2. wrong name '{}' in warning
// -----------------------------
// g++ -W -Wall -c g.cpp -DF2=1
// g.cpp: In method `void B<char>::f(int)':
// g.cpp:40: instantiated from here
// g.cpp:25: could not convert `{}' to `A<char> &'
// g.cpp:15: in passing argument 2 of `B<char>::f<A<char> >(int, A<char>
&)'
// why a parse error ? :
// g++ -W -Wall -c g.cpp -DF2=2
// g.cpp: In method `void B<T>::f(int)':
// g.cpp:28: parse error before `)'
// g++ -W -Wall -c g.cpp -DF2=3
// g.cpp: In method `void B<char>::f(int)':
// g.cpp:40: instantiated from here
// g.cpp:31: warning: left-hand operand of comma expression has no effect
// g.cpp:31: could not convert `{}' to `A<char> &'
// g.cpp:15: in passing argument 2 of `B<char>::f<A<char> >(int, A<char>
&)'
// 3. good name, but why can gcc not convert ?
// --> better error message would be nice (like : lvalue required)
// (also : why 'A<T>()' and not 'A<T>' ?)
// -------------------------------------------
// g++ -W -Wall -c g.cpp -DF1 -DF2=1
// g.cpp: In method `void B<char>::f(int)':
// g.cpp:40: instantiated from here
// g.cpp:25: could not convert `A<char>()' to `A<char> &'
// g.cpp:15: in passing argument 2 of `B<char>::f<A<char> >(int, A<char>
&)'
// why a parse error ? :
// g++ -W -Wall -c g.cpp -DF1 -DF2=2
// g.cpp: In method `void B<T>::f(int)':
// g.cpp:28: parse error before `)'
// g++ -W -Wall -c g.cpp -DF1 -DF2=3
// g.cpp: In method `void B<char>::f(int)':
// g.cpp:40: instantiated from here
// g.cpp:31: warning: left-hand operand of comma expression has no effect
// g.cpp:31: could not convert `A<char>()' to `A<char> &'
// g.cpp:15: in passing argument 2 of `B<char>::f<A<char> >(int, A<char>
&)'
--
Jeroen Dobbelaere
Software Design Engineer
Micro-Matic Research < http://www.mmr.be >
More information about the Gcc-bugs
mailing list