public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/11694] New: Template member class of template class mix-up
@ 2003-07-28 13:55 cholm at nbi dot dk
2003-07-28 14:08 ` [Bug c++/11694] " pinskia at physics dot uc dot edu
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: cholm at nbi dot dk @ 2003-07-28 13:55 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11694
Summary: Template member class of template class mix-up
Product: gcc
Version: 3.2.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: cholm at nbi dot dk
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
Hi GCC developers,
I think I stumbled on a bug in G++. It has to do with template nested classes
in template classes. It seems that there's something missing in the parse.
Maybe it has something to do with the `second template pass bug'?
Please find the file `baz.cc' below.
prompt> g++-3.2 baz.cc -o baz
g++-3.2 baz.cc -o baz
baz.cc: In instantiation of `bar<double>':
baz.cc:47: instantiated from here
baz.cc:20: internal error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://www.gnu.org/software/gcc/bugs.html> for instructions.
My machine is a dual Intel Celeron, running Linux 2.4.18 SMP, with
GLibC version 2.2.5-11. The distribution is Debian GNU/Linux 3.0
(woody) with some extra packages from testing (sarge).
GCC is:
prompt> gcc-3.2 -v
Reading specs from /usr/lib/gcc-lib/i386-linux/3.2.2/specs
Configured with: ../src/configure -v --enable-
languages=c,c++,java,f77,proto,p
ascal,objc,ada --prefix=/usr --mandir=/usr/share/man --
infodir=/usr/share/info -
-with-gxx-include-dir=/usr/include/c++/3.2 --enable-shared --with-system-zlib -
-
enable-nls --without-included-gettext --disable-__cxa_atexit --enable-java-
gc=bo
ehm --enable-objc-gc i386-linux
Thread model: posix
gcc version 3.2.2
Note, that the `baz.cc' file compiles fine with Intel C++ version
7.0.
If I change the source, so that the `bar' class takes two template
parameters, like:
template <typename A, typename B=A>
struct bar : public foo<A, B>
{
typedef foo<A , B> base_type;
typedef base_type::helper<1> helper_type;
helper_type _help;
bar(const A& a) : base_type(a, a), _help() {}
virtual int doit() { return _help.doit(_a,_b); }
};
it compiles fine.
If I in the `baz' class changes the definition of `helper_type' to
directly reference the sub-class of `foo<A,B>', like:
template <typename A>
struct baz : public bar<A>
{
typedef bar<A> base_type;
typedef foo<A,A>::helper<1> helper_type;
helper_type* _helper;
baz() : base_type(42) { _helper = new helper_type(2); }
int doit() { return _helper->doit(_a,_b); }
};
then I get:
> g++-3.2 baz.cc -o baz
bar.cc: In constructor `baz<A>::baz() [with A = double]':
bar.cc:50: instantiated from here
bar.cc:36: invalid use of undefined type `struct foo<double, B>::helper<1>'
bar.cc:6: declaration of `struct foo<double, B>::helper<1>'
bar.cc: In member function `int baz<A>::doit() [with A = double]':
bar.cc:51: instantiated from here
bar.cc:37: no matching function for call to `foo<double, B>::helper<1>::doit(
double&, double&)'
Again, Intel C++ version 7.0 compiles that just fine
Only if I instancises `foo<A,B>::helper<C>' with explicit types for
`A' and `B', like:
template <typename A>
struct baz : public bar<A>
{
typedef bar<A> base_type;
typedef foo<double,double>::helper<1> helper_type;
helper_type* _helper;
baz() : base_type(42) { _helper = new helper_type(2); }
int doit() { return _helper->doit(_a,_b); }
};
can I get an error free compile
The contens of `baz.cc' follows below:
//====================================================================
template <typename A, typename B>
struct foo {
template <int C>
struct helper
{
helper() {}
int doit(const A& a, const B& b) { return C + int(a) + int(b); }
};
A _a;
B _b;
foo() : _a(0), _b(0) {}
foo(const A& a, const B& b) : _a(a), _b(b) {}
virtual int doit() { return 0; }
};
//====================================================================
template <typename A>
struct bar : public foo<A, A>
{
typedef foo<A , A> base_type;
typedef base_type::helper<1> helper_type;
helper_type _help;
bar(const A& a) : base_type(a, a), _help() {}
virtual int doit() { return _help.doit(_a,_b); }
};
//====================================================================
template <typename A>
struct baz : public bar<A>
{
typedef bar<A> base_type;
typedef typename base_type::helper_type helper_type;
helper_type* _helper;
baz() : base_type(42) { _helper = new helper_type(); }
int doit() { return _helper->doit(_a,_b); }
};
//====================================================================
int
main(int argc, char** argv)
{
foo<double, double> foo(3.14, 42);
bar<double> b1(3.14);
int a1 = b1.doit();
baz<double> b2;
int a2 = b2.doit();
return 0;
}
//
// EOF of `baz.cc'
//
Yours,
___ | Christian Holm Christensen
|_| | -------------------------------------------------------------
| | Address: Sankt Hansgade 23, 1. th. Phone: (+45) 35 35 96 91
_| DK-2200 Copenhagen N Cell: (+45) 24 61 85 91
_| Denmark Office: (+45) 353 25 305
____| Email: cholm@nbi.dk Web: www.nbi.dk/~cholm
| |
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/11694] Template member class of template class mix-up
2003-07-28 13:55 [Bug c++/11694] New: Template member class of template class mix-up cholm at nbi dot dk
@ 2003-07-28 14:08 ` pinskia at physics dot uc dot edu
2003-07-29 9:57 ` [Bug c++/11694] ICE with missing typename/template keywords ehrhardt at mathematik dot uni-ulm dot de
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at physics dot uc dot edu @ 2003-07-28 14:08 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11694
------- Additional Comments From pinskia at physics dot uc dot edu 2003-07-28 14:08 -------
icc 6.0 rejects it with strict turned on (-Xc):
tin:~/src/gnu/gcctest>/opt/intel/compiler60/ia32/bin/icc pr11694.cc -Xc
pr11694.cc
pr11694.cc(21): error: nontype "foo<A, B>::helper [with A=A, B=A]" is not a template
typedef base_type::helper<1> helper_type;
^
pr11694.cc(25): error: identifier "_a" is undefined
virtual int doit() { return _help.doit(_a,_b); }
^
pr11694.cc(25): error: identifier "_b" is undefined
virtual int doit() { return _help.doit(_a,_b); }
^
pr11694.cc(36): error: identifier "_a" is undefined
int doit() { return _helper->doit(_a,_b); }
^
pr11694.cc(36): error: identifier "_b" is undefined
int doit() { return _helper->doit(_a,_b); }
^
compilation aborted for pr11694.cc (code 2)
The mainline (20030728) of GCC rejects it also:
pr11694.cc:21: error: ISO C++ forbids declaration of `helper' with no type
pr11694.cc:21: error: cannot declare member `foo<A, A>::helper' within `bar<A>'
pr11694.cc:21: error: expected `;'
pr11694.cc:22: error: `helper_type' does not name a type
pr11694.cc: In constructor `bar<A>::bar(const A&)':
pr11694.cc:24: error: class `bar<A>' does not have any field named `_help'
pr11694.cc: In member function `virtual int bar<A>::doit()':
pr11694.cc:25: error: `_help' undeclared (first use this function)
pr11694.cc:25: error: (Each undeclared identifier is reported only once for
each function it appears in.)
pr11694.cc:25: error: `_a' undeclared (first use this function)
pr11694.cc:25: error: `_b' undeclared (first use this function)
pr11694.cc: In member function `int baz<A>::doit()':
pr11694.cc:36: error: `_a' undeclared (first use this function)
pr11694.cc:36: error: `_b' undeclared (first use this function)
pr11694.cc: At global scope:
pr11694.cc: In instantiation of `baz<double>':
pr11694.cc:49: instantiated from here
pr11694.cc:33: error: no type named `helper_type' in `struct bar<double>'
pr11694.cc:34: error: no type named `helper_type' in `struct bar<double>'
pr11694.cc: In constructor `baz<A>::baz() [with A = double]':
pr11694.cc:49: instantiated from here
pr11694.cc:35: error: no type named `helper_type' in `struct bar<double>'
pr11694.cc:35: error: `_helper' undeclared (first use this function)
pr11694.cc: In member function `int baz<A>::doit() [with A = double]':
pr11694.cc:50: instantiated from here
pr11694.cc:36: error: `_helper' undeclared (first use this function)
GCC 2.95.3 also rejects it:
pr11694.cc: In method `bar<double>::bar(const double &)':
pr11694.cc:46: instantiated from here
pr11694.cc:24: no matching function for call to `foo<double,B>::helper<1>::helper
(foo<double,B>::helper<1>)'
pr11694.cc: In method `int bar<double>::doit()':
pr11694.cc:47: instantiated from here
pr11694.cc:25: no matching function for call to `foo<double,B>::helper<1>::doit (double &,
double &)'
pr11694.cc: In method `baz<double>::baz()':
pr11694.cc:49: instantiated from here
pr11694.cc:35: invalid use of undefined type `struct foo<double,B>::helper<1>'
pr11694.cc:8: forward declaration of `struct foo<double,B>::helper<1>'
pr11694.cc: In method `int baz<double>::doit()':
pr11694.cc:50: instantiated from here
pr11694.cc:36: no matching function for call to `foo<double,B>::helper<1>::doit (double &,
double &)'
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/11694] ICE with missing typename/template keywords
2003-07-28 13:55 [Bug c++/11694] New: Template member class of template class mix-up cholm at nbi dot dk
2003-07-28 14:08 ` [Bug c++/11694] " pinskia at physics dot uc dot edu
@ 2003-07-29 9:57 ` ehrhardt at mathematik dot uni-ulm dot de
2003-07-29 12:16 ` [Bug c++/11694] [3.3 Regression] " pinskia at physics dot uc dot edu
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: ehrhardt at mathematik dot uni-ulm dot de @ 2003-07-29 9:57 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11694
ehrhardt at mathematik dot uni-ulm dot de changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Keywords| |ice-on-invalid-code
Priority|P2 |P3
Last reconfirmed|0000-00-00 00:00:00 |2003-07-29 09:57:44
date| |
Summary|Template member class of |ICE with missing
|template class mix-up |typename/template keywords
Target Milestone|3.4 |3.3.2
Version|3.2.2 |3.3.1
------- Additional Comments From ehrhardt at mathematik dot uni-ulm dot de 2003-07-29 09:57 -------
The code is invalid. This line:
typedef foo<A, A>::helper<1> helper_type;
must be written as
typedef typename foo<A, A>::template helper<1> helper_type;
However, gcc should not issue an Internal Compiler Error. This is
fixed in 3.4. Note that there are two different ICEs, one if both
typename and template are are missing. There's another one if
template is there but typename is missing.
Reduced example:
template <typename , typename >
struct foo {
template <int> struct helper { };
};
template <typename A>
struct bar : public foo<A, A>
{
typedef foo<A, A>::helper<1> helper_type;
};
bar<double> b1();
regards Christian
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/11694] [3.3 Regression] ICE with missing typename/template keywords
2003-07-28 13:55 [Bug c++/11694] New: Template member class of template class mix-up cholm at nbi dot dk
2003-07-28 14:08 ` [Bug c++/11694] " pinskia at physics dot uc dot edu
2003-07-29 9:57 ` [Bug c++/11694] ICE with missing typename/template keywords ehrhardt at mathematik dot uni-ulm dot de
@ 2003-07-29 12:16 ` pinskia at physics dot uc dot edu
2003-10-16 9:24 ` mmitchel at gcc dot gnu dot org
2003-10-19 22:18 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at physics dot uc dot edu @ 2003-07-29 12:16 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11694
pinskia at physics dot uc dot edu changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|ICE with missing |[3.3 Regression] ICE with
|typename/template keywords |missing typename/template
| |keywords
------- Additional Comments From pinskia at physics dot uc dot edu 2003-07-29 12:16 -------
3.3.1 (20030707) does not ICE on the reduced testcase but does on the full testcase
Also the full source does not ICE in 2.95.3 so making this a regression.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/11694] [3.3 Regression] ICE with missing typename/template keywords
2003-07-28 13:55 [Bug c++/11694] New: Template member class of template class mix-up cholm at nbi dot dk
` (2 preceding siblings ...)
2003-07-29 12:16 ` [Bug c++/11694] [3.3 Regression] " pinskia at physics dot uc dot edu
@ 2003-10-16 9:24 ` mmitchel at gcc dot gnu dot org
2003-10-19 22:18 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2003-10-16 9:24 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11694
mmitchel at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|3.3.2 |3.3.3
------- Additional Comments From mmitchel at gcc dot gnu dot org 2003-10-16 09:24 -------
Postponed until GCC 3.3.3.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/11694] [3.3 Regression] ICE with missing typename/template keywords
2003-07-28 13:55 [Bug c++/11694] New: Template member class of template class mix-up cholm at nbi dot dk
` (3 preceding siblings ...)
2003-10-16 9:24 ` mmitchel at gcc dot gnu dot org
@ 2003-10-19 22:18 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2003-10-19 22:18 UTC (permalink / raw)
To: gcc-bugs
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11694
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
Target Milestone|3.3.3 |3.4
------- Additional Comments From pinskia at gcc dot gnu dot org 2003-10-19 22:12 -------
Closing as fixed as this is an error-recovery problem and it is fixed on the mainline.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2003-10-19 22:12 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-28 13:55 [Bug c++/11694] New: Template member class of template class mix-up cholm at nbi dot dk
2003-07-28 14:08 ` [Bug c++/11694] " pinskia at physics dot uc dot edu
2003-07-29 9:57 ` [Bug c++/11694] ICE with missing typename/template keywords ehrhardt at mathematik dot uni-ulm dot de
2003-07-29 12:16 ` [Bug c++/11694] [3.3 Regression] " pinskia at physics dot uc dot edu
2003-10-16 9:24 ` mmitchel at gcc dot gnu dot org
2003-10-19 22:18 ` pinskia at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).