This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Template member type problem


Hi,

I'm hesitant to submit this because I know most
"bugs" are really people not adhering to the
standard... I'd appreciate any thoughts on what
is wrong with this very short sample.

The following sample code compiles cleanly on
older versions of g++ (2.7.2.1 works) and the
native compiler on my sun workstation but more
recent versions do not work:

#include <iostream.h>

class myclass {
public:
  typedef myclass *pnt_myclass;
  int x;
};

template<typename X>
void tryit(X &x) {
  X::pnt_myclass xpnt=&x; // This will not parse
  xpnt->x=3;
}

main(int argc, char **argv) {

  myclass fred;
  tryit(fred);
  cout << "x=" << fred.x << endl;

}

I've attached the .ii file and the output
from g++ is below.

Thanks!

Joe.

-- 
Joe Morris           morris50@llnl.gov
Geophysics and Global Security Division
Lawrence Livermore National Laboratory
PO Box 808, L-206, Livermore, CA 94551-9900


Output from /usr/local/bin/g++ -v --save-temps -o test test.cpp

Reading specs from
/usr/local/bin/../lib/gcc-lib/i386-pc-linux-gnu/2.96/specs
gcc version 2.96 20000615 (experimental)
 /usr/local/bin/../lib/gcc-lib/i386-pc-linux-gnu/2.96/cpp -lang-c++ -v
-iprefix /usr/local/bin/../lib/gcc-lib/i386-pc-linux-gnu/2.96/
-D__GNUC__=2 -D__GNUG__=2 -D__GNUC_MINOR__=96 -D__GNUC_PATCHLEVEL__=0
-D__cplusplus -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__
-D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -Acpu(i386)
-Amachine(i386) -Di386 -D__i386 -D__i386__ -D__tune_i386__ test.cpp
test.ii
GNU CPP version 2.96 20000615 (experimental) (cpplib)
 (i386 Linux/ELF)
ignoring nonexistent directory
`/tmp/gcc-20000615-root/usr/local/include/g++-3'
ignoring nonexistent directory
`/tmp/gcc-20000615-root/usr/local/lib/gcc-lib/i386-pc-linux-gnu/2.96/include'
ignoring nonexistent directory
`/tmp/gcc-20000615-root/usr/local/i386-pc-linux-gnu/include'
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include/g++-3
 /usr/local/lib/gcc-lib/i386-pc-linux-gnu/2.96/include
 /usr/local/i386-pc-linux-gnu/include
 /usr/local/include
 /usr/include
End of search list.
 /usr/local/bin/../lib/gcc-lib/i386-pc-linux-gnu/2.96/cc1plus test.ii
-quiet -dumpbase test.cc -version -o test.s
GNU C++ version 2.96 20000615 (experimental) (i386-pc-linux-gnu)
compiled by GNU C version 2.96 20000615 (experimental).
test.cpp: In function `void tryit (X &)':
test.cpp:11: parse error before `='
test.cpp: In function `void tryit (X &) [with X = myclass]':
test.cpp:18:   instantiated from here
test.cpp:12: `xpnt' undeclared (first use this function)
test.cpp:12: (Each undeclared identifier is reported only once for each
function it appears in.)

test.ii


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]