This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/35008] New: Bug in processing nested typedef in nested template class in method definition
- From: "wirawan0 at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 29 Jan 2008 02:35:10 -0000
- Subject: [Bug c++/35008] New: Bug in processing nested typedef in nested template class in method definition
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The following testcase fails to compile:
template <typename data1> struct outer1
{
typedef int my_value_type; // define a nested datatype
template <typename servert> struct inner1
{
typedef outer1<data1> myboss;
// borrow the boss's datatype << -- don't reduce or change this one:
typedef typename myboss::my_value_type my_value_type;
my_value_type return_x();
};
};
// g++ 4 choked on this one:
template <typename data1>
template <typename servert>
typename outer1<data1>::template inner1<servert>::my_value_type
outer1<data1>::inner1<servert>::return_x()
{
return 4;
}
void testme()
{
outer1<float>::inner1<int> Inner1;
int rslt = Inner1.return_x(); // to instantiate and cause error
}
It is basically like this:
* outer1 class template has a nested datatype called "my_value_type"
* inner1 borrows the "my_value_type" from outer1 (its parent)
Then when we want to instantiate return_x() above, g++ gives the following
error:
template-typename4.cpp:19: error: prototype for ?typename
outer1<data1>::inner1<servert>::my_value_type
outer1<data1>::inner1<servert>::return_x()? does not match any in class
?outer1<data1>::inner1<servert>?
template-typename4.cpp:10: error: candidate is: typename
outer1<data1>::my_value_type outer1<data1>::inner1<servert>::return_x()
template-typename4.cpp:19: error: template definition of non-template ?typename
outer1<data1>::inner1<servert>::my_value_type
outer1<data1>::inner1<servert>::return_x()?
I can work around this by changing line 18 above:
typename outer1<data1>::template inner1<servert>::my_value_type
to
typename outer1<data1>::my_value_type
then it would compile. But I think this is a bug. It used to compile with g++
3. Other compilers such as Intel C++ (version 9.1), PGI C++ 7 all accept this
language construct.
--
Summary: Bug in processing nested typedef in nested template
class in method definition
Product: gcc
Version: 4.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: wirawan0 at gmail dot com
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35008