Possible bug with gcc-2.95.2 wrt templates, typedefs & -pedantic

Andrew Pollard andrew@odie.demon.co.uk
Fri Jun 9 08:12:00 GMT 2000


 I'm not sure that this is a bug or not, but have noticed a change from
egcs-1.1.2 to gcc-2.95.2. I've looked at the draft C++ standard I have
and can't see that this has been changed.

I am using RedHat6.2/i386 with

% g++ -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)


% /usr/local/gcc-2.95.2-i686-pc-linux-gnu/bin/g++ -v
Reading specs from /usr/local/gcc-2.95.2-i686-pc-linux-gnu/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/specs
gcc version 2.95.2 19991024 (release)

With the following program fragment

template<typename X>
struct TA {
	typedef X FOO;

template<typename X>
struct TB : public TA<X> {
	TB(X) {}

template<typename X>
struct TC : public TA<X> {
	TC(TA<X>::FOO) {}

template<typename X>
struct TD : public TA<X> {
	TD(FOO) {}

% gcc -c a.cc
% gcc -pedantic -c a.cc
% /usr/local/gcc-2.95.2-i686-pc-linux-gnu/bin/g++ -c a.cc
% /usr/local/gcc-2.95.2-i686-pc-linux-gnu/bin/g++ -pedantic -c a.cc
a.cc:18: parse error before `)'
a.cc:18: missing ';' before right brace

(the line containing 'TD(FOO) {}')

ie, you can't seem to use a typedef from a parent template class in a
child class when using -pedantic and gcc-2.95.2 without fully qualifying
it. The TB and TC classes are 'equivalent' in their functionality (which
shows there is an easy work-around).

The code without all the templates (ie hardcoding an int as the template
parameter X)

struct TA {
	typedef int FOO;

struct TB : public TA {
	TB(int) {}

struct TC : public TA {
	TC(TA::FOO) {}

struct TD : public TA {
	TD(FOO) {}

% gcc -c b.cc
% gcc -pedantic -c b.cc
% /usr/local/gcc-2.95.2-i686-pc-linux-gnu/bin/g++ -c b.cc
% /usr/local/gcc-2.95.2-i686-pc-linux-gnu/bin/g++ -pedantic -c b.cc

all compiles fine.

Have I just misread the C++ spec (wouldn't surprise me - it's a bugger to
read :-) or is it a bug?

Andrew Pollard, ASI/Brooks Automation UK. | home: andrew@odie.demon.co.uk
2 Milbanke Court, Milbanke Way, Bracknell | work: Andrew_Pollard@autosim.com
Tel/Fax: (+44(0)1344) 426486x103 / 426615 | http://www.odie.demon.co.uk

More information about the Gcc-bugs mailing list