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]

templates: crashes on ctor initting templated base class


(Well, actually, more specifically crashes on ctor initting a template
parameter base class template.)

Vitals: egcs-1.1.1, linux 2.0.34, simple compile (g++ test.cc), full
source 5 lines below.

This is starting to use some of the more advanced template options,
so I'm not 100% sure of the syntax, but I think:

	class A;
	template<template<class Ignored> class base> class C : public base<A> {
	 public:
	    C(A& newa) : base<A>(newa) {}
	};

ought to be correct.  egcs crashes trying to call base<A>(newa), and
begs me to send this message to the list ("internal compiler error").
It seems to correctly recognize what's going on here; if I change the
name of the constructor only (e.g., to D) it complains that "only
ctors take base initializers."  (This helps me believe this syntax is
correct; I've tried throwing the keyword 'template' around in several
places, with or without empty <>, and get crashes anyway.)  It crashes
similarly if I define class A and an appropriate ctor, a la:

	class A {public: int a; A(A& newa) : a(newa.a) {} };

I've debugged this a tiny bit (see note below) and indeed, it looks
like it's trying to dereference a pointer whose value is 3.  I think
I'd have to know the code a lot better to figure out why...

BTW, the above is a slightly simplified version for debugging of what
I really want to do, which is:

	template<class A, template<class Ignored> class base> class C : 
		public base<A> {
	 public:
	    C(A& newa) : base<A>(newa) {}
	};

which gets a similar response from egcs.  (Which is much better than
from any other compiler!  egcs's template features seem to be MILES
ahead of everyone else; all other compilers have no idea what I mean
here.  Kudos, and thanks!)

BTW, I'm not (yet) subscribed to this list, so please Cc: responses to
me (at grg@ai.mit.edu).  Thanks.

--grg@ai.mit.edu



PS -- Note from my experience starting to track this down: to an
"outsider" it's not at all clear how to even start debugging the
system -- "gdb g++" was not the right thing to do in this case, as the
problem was in cc1plus.  I barely had an idea cc1plus existed, or how
it was used...  Anyway, it seems the project would benefit from
lowering barriers to entry like this by having a simple writeup on the
major parts of the system, what they do, how they interact, where they
& their source code live, and how to begin tracking down a bug (how to
run the debugger, on what).  Note that I haven't asked for a
description of the internals of the compiler, as I know that's too
complicated to have any chance of getting written up and changes too
fast anyway; just a primer that will help people start to debug their
own problems and eventually submit patches rather than bug reports...


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