This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
bug report: templates, debugging information
- To: egcs-bugs at cygnus dot com
- Subject: bug report: templates, debugging information
- From: chauvin at cauchy dot ee dot washington dot edu (Todd Chauvin)
- Date: Sun, 2 Nov 1997 16:39:18 -0800 (PST)
- Reply-To: chauvin at ee dot washington dot edu
hi,
i've attached a tiny do-nothing program that triggers what i think might be a
tiny bug in egcs-971031 (also egcs-971023, earlier snapshots not tested).
i apologize for spreading the test case over three files, but i haven't
been able to isolate it with fewer source files.
compile the example "-g" with no other flags.
g++ -g -o main Array.cc main.cc
my platform: ultrasparc1, solaris2.5
% g++ -v
Reading specs from /home11/local/Solaris/egcs-971031/lib/
gcc-lib/sparc-sun-solaris2.5/egcs-2.90.15/specs
gcc version egcs-2.90.15 971031 (gcc2-970802 experimental)
the program executes correctly, but egcs gets line numbers confused between
the source and header files. as supplied, the compilation fails
(as it should) with the error:
% g++ -g -c Array.cc
Array.h: In method `class ostream & Array<int>::print(class ostream &) const':
Array.h:19: `size' undeclared (first use this function)
Array.h:19: (Each undeclared identifier is reported only once
Array.h:19: for each function it appears in.)
the line number is correct, but it goes with Array.cc, not Array.h.
removing the compile-time error (see comment HERE in Array.cc) results in
a working program, but the debug information still puts the line numbers
with the header file instead of the source file. stepping through
the print method (cout << p1) with gdb4.16 illustrates the problem:
Breakpoint 1, main () at main.cc:5
5 cout << p1;
(gdb) s
operator<< (s=@0x35a50, x=@0xeffff9c4) at Array.h:12
12 { return(x.print(s)); };
(gdb) s
Array<int>::print (this=0xeffff9c4, s=@0x35a50) at Array.h:18
Line number 18 out of range; Array.h has 12 lines.
gcc2.7.2.1 works as expected for this example.
this behavior appears sensitive to how operator<< is declared/defined.
regards,
todd chauvin
--------------------------------Array.h-----------------------------------------
#include <iostream.h>
template<class T>
class Array {
private:
int size_;
public:
Array(int num) { resize(num); };
void resize(int newsize);
ostream& print(ostream &s) const;
};
inline ostream& operator<<(ostream &s, const Array<int> &x)
{ return(x.print(s)); };
--------------------------------Array.cc----------------------------------------
#include <iostream.h>
#include "Array.h"
template<class T> void Array<T>::resize(int newsize)
{
size_=newsize;
}
template<class T> ostream& Array<T>::print(ostream &s) const
{
//
// HERE:
//
// As written, the compile-time error message gives the line number
// in Array.cc but specifies the file name as Array.h.
//
// to get a program that compiles (but still exhibits the confusion)
// move the comment down one line
//
//s << size_ << endl;
s << size() << endl;
return(s);
}
//
// Explicit instantiations
//
template class Array<int>;
--------------------------------main.cc-----------------------------------------
#include "Array.h"
int main(void)
{
Array<int> p1(10);
cout << p1;
return(0);
}