This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
ICE using member templates.
- To: gcc-bugs at gcc dot gnu dot org
- Subject: ICE using member templates.
- From: Ken Yarnall <yarnall at lvc dot edu>
- Date: Sat, 01 Apr 2000 09:45:20 -0500
- Organization: Lebanon Valley College
I have a language question and a bug report.
Language question: So far as I can tell from the standard, when
referring to a template member of the current template, you do not
need the "template" qualifier. That is, the following code is
correct:
//----------------gccICE.cpp----------------------
template <class A>
class X {
public:
typedef void (*FUNC)();
template<class B>
X(B b) : it(&func<B>) {}
private:
FUNC it;
template <class B>
static void func() {}
};
int
main()
{
X<int> x(1.001);
}
//----------------gccICE.cpp----------------------
In particular, the initialization of "it" in the c'tor; this
(should be/is) legal, right? The compiler can certainly tell that
func is a template. My reading of the standard is that one
only needs the template qualifier when referring to members of
a class represented by a template parameter.
The code above produces an ICE when compiled with 2.95.2, and
with the 3/27/00 snapshot. Output below:
--------------------------------------------------
% /usr/local/gcc-exp/bin/g++ -v --save-temps gccICE.cpp
Reading specs from /usr/local/gcc-exp/lib/gcc-lib/i686-pc-linux-gnu/2.96/specs
gcc version 2.96 20000327 (experimental)
/usr/local/gcc-exp/lib/gcc-lib/i686-pc-linux-gnu/2.96/cpp -lang-c++ -v -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_pentiumpro__ gccICE.cpp
gccICE.ii
GNU CPP version 2.96 20000327 (experimental) (cpplib)
(i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
.
/home/facstaff/yarnall/include
/usr/local/gcc-exp/include/g++-3
/usr/local/include
/usr/local/gcc-exp/lib/gcc-lib/i686-pc-linux-gnu/2.96/include
/usr/local/gcc-exp/i686-pc-linux-gnu/include
/usr/include
End of search list.
/usr/local/gcc-exp/lib/gcc-lib/i686-pc-linux-gnu/2.96/cc1plus gccICE.ii -quiet -dumpbase
gccICE.cc -version -o gccICE.s
GNU C++ version 2.96 20000327 (experimental) (i686-pc-linux-gnu) compiled by GNU C version
2.96 20000327 (experimental).
gccICE.cpp: In method `X<A>::X (B) [with B = double, A = int]':
gccICE.cpp:21: instantiated from here
gccICE.cpp:8: Internal compiler error.
gccICE.cpp:8: Please submit a full bug report.
gccICE.cpp:8: See <URL:http://www.gnu.org/software/gcc/bugs.html> for
gccICE.cpp:8: instructions.
--------------------------------------------------
I reported this bug about 6 months ago (I'm not intending to nag, but I've noticed that
Martin is generally remarkably quick at responding to bug reports, and no one ever
responded to this one, so I fear it may have slipped through the cracks). At the time, I
noted the fact that if I change the initialization of it to
it(&X:: template func<B>)
then the code is compiled (correctly) without error.
Cheers,
Ken