This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Possible bug with gcc-2.95.2 wrt templates, typedefs & -pedantic
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Possible bug with gcc-2.95.2 wrt templates, typedefs & -pedantic
- From: Andrew Pollard <andrew at odie dot demon dot co dot uk>
- Date: Fri, 9 Jun 2000 14:58:00 +0100
Hi,
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)
and
% /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
a.cc
-----------------------------------------------------------------------------
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)
b.cc:
-----------------------------------------------------------------------------
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.
--
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