This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/11501] New: template environmet confuses g++, and prohibits compiling valid code
- From: "eikescholz at gmx dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 11 Jul 2003 16:30:07 -0000
- Subject: [Bug c++/11501] New: template environmet confuses g++, and prohibits compiling valid code
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11501
Summary: template environmet confuses g++, and prohibits
compiling valid code
Product: gcc
Version: 3.2.3
Status: UNCONFIRMED
Severity: critical
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: eikescholz at gmx dot de
CC: gcc-bugs at gcc dot gnu dot org
The following code:
----------------------bug.cc ----------------------------
template< unsigned int flavor >
class A
{
public:
template<unsigned int _flavor> A<_flavor>& change_flavor()
{
typedef A<_flavor> new_flavor;
return reinterpret_cast< new_flavor& >( *this );
};
};
// this one compiles
int kungfoo()
{
A<1> test;
A<2> test2( test.change_flavor<2>() );
return 1;
}
#if 1
// this one not
template<int k> int kungfoo_template()
{
A<1> test;
A<2> test2( test.change_flavor<2>() );
return k;
}
#endif
int main()
{
return kungfoo();
// return kungfoo_template<1>();
}
------------------------- end bug.cc ----------------------
produces:
----
cptchaos@motion debug_g++ $ g++ bug.cc -o bug
bug.cc: In function `int kungfoo_template()':
bug.cc:31: syntax error before `)' token
----
with:
----
cptchaos@motion debug_g++ $ g++ --version
g++ (GCC) 3.2.3 20030422 (Gentoo Linux 1.4 3.2.3-r1, propolice)
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
----
if you change the #if 1 to #if 0 the file will compile.
Because off the fact, that the not templated function uses exact the same
syntax like the templatet one, I assume that the systax errror is a false
positive, that prohibits compiling valid code.
I could reproduce the error with g++-2.95 and g++-3.3 on my debian system:
---
station% gcc-2.95 bug.cc
bug.cc: In function `int kungfoo_template()':
bug.cc:31: parse error before `('
station% gcc-2.95 --version
2.95.4
station% gcc-3.3 bug.cc
bug.cc: In function `int kungfoo_template()':
bug.cc:31: error: parse error before `)' token
station% gcc-3.3 --version
gcc-3.3 (GCC) 3.3 (Debian)
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
---
PS: I need this reinterpret_cast tric for some aggressive compile_time
optimisations, and I now what I am doing there, and it makes sense.