Article View: gnu.gcc.bug
Article #3gcc-2.2.2 handling of C++ const member functions in templates
From: Paul N. Hilfinger
Date: Tue, 27 Oct 1992 22:58
Date: Tue, 27 Oct 1992 22:58
79 lines
2602 bytes
2602 bytes
The attached C++ file as input to gcc-2.2.2 causes an error message
that I believe to be incorrect. Session transcript:
----------------------------------------------------------------------
tully 421% gcc -c -v templates-a.C
Reading specs from /usr/sww/lib/gcc-lib/sun4/2.2.2/specs
gcc version 2.2.2
/usr/sww/lib/gcc-lib/sun4/2.2.2/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix templates-a.C /usr/tmp/cca16197.i
GNU CPP version 2.2.2 (sparc)
/usr/sww/lib/gcc-lib/sun4/2.2.2/cc1plus /usr/tmp/cca16197.i -quiet -dumpbase templates-a.cc -version -o /usr/tmp/cca16197.s
GNU C++ version 2.2.2 (sparc) compiled by GNU C version 2.2.2.
templates.C: In function `int main ()':
templates.C:19: template for method `colsOf' doesn't match any in class `Array2D<double>'
templates.C:19: template for method `rowsOf' doesn't match any in class `Array2D<double>'
----------------------------------------------------------------------
The two error messages regarding colsOf and rowsOf seem to be wrong.
If the "const" qualifier is removed from these member functions, no
message results.
Source file templates-a.C (pre-processed):
----------------------------------cut here------------------------------------
# 1 "templates.C"
template<class T> class Array2D {
public:
Array2D(int m, int n);
T& operator()(int i, int j);
int rowsOf() const ;
int colsOf() const ;
private:
T* data;
int M, N;
};
template<class T> Array2D<T>::Array2D(int m, int n) :
M(m), N(n), data(new T[m*n])
{}
template<class T> T& Array2D<T>::operator()(int i, int j)
{
return data[i * N + j];
}
template<class T> int Array2D<T>::rowsOf() const
{
return M;
}
template<class T> int Array2D<T>::colsOf() const
{
return N;
}
int main()
{
Array2D<double> A(2, 3);
for (int i = 0; i < A.rowsOf(); i += 1)
for (int j = 0; j < A.colsOf(); i += 1)
A(i,j) = i / 3.0 + j / 17.0;
return 0;
}
Technical Details
Message-ID:
<9210272258.AA16202@tully.CS.Berkeley.EDU.iliad>Path:
arc1-ca.pugleaf.net!sparky!uunet!convex!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!tully.cs.berkeley.edu!hilfingrShow Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug Path: arc1-ca.pugleaf.net!sparky!uunet!convex!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!tully.cs.berkeley.edu!hilfingr From: hilfingr@tully.cs.berkeley.edu (Paul N. Hilfinger) Subject: gcc-2.2.2 handling of C++ const member functions in templates Message-ID: <9210272258.AA16202@tully.CS.Berkeley.EDU.iliad> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Tue, 27 Oct 1992 22:58:00 GMT Approved: bug-gcc@prep.ai.mit.edu Lines: 81