-pedantic too pedantic about templates
Stefan Schwarzer
sts@ica1.uni-stuttgart.de
Sat May 22 12:55:00 GMT 1999
// the following code (which is part of the testsuite) fails to
// compile with egcs-2.93.21 19990502 on solaris/sparc and osf1/alpha
// ONLY/AT LEAST when the -pedantic option is used
// (otherwise it compiles silently and executes correctly)
// I.m.h.o., the code is valid ISO C++ and the compiler should accept it
//sts_iarr.C: In method `struct Outer<1>::Inner Outer<2>::operator [](int) const':
//sts_iarr.C:45: instantiated from here
//sts_iarr.C:18: invalid use of member `Outer<1>::Inner'
// sts@ica1.uni-stuttgart.de
// should compile (with -pedantic) and return 0
template <int N>
struct Outer{
struct Inner{
Inner(int n): sum(n){}
typename Outer<N-1>::Inner operator[](int n) const
{ return Outer<N-1>::Inner(sum + n); }
int sum;
};
typename Outer<N-1>::Inner operator[](int n) const
{ return Outer<N-1>::Inner(n); }
};
// specializations for N==1
template<>
struct Outer<1> {
struct Inner {
Inner(int n): sum(n){}
int operator[](int n) const
{ return sum+n; }
int sum;
};
int operator[](int n) const
{ return n; }
};
int main()
{
Outer<1> sum1;
//std::cout << sum1[1] << "\n";
Outer<2> sum2;
//std::cout << sum2[1][1] << "\n";
return sum1[1] + sum2[1][1] - 3;
}
More information about the Gcc-bugs
mailing list