This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/8858: Gcc "rebinds" template member names.
- From: eivuokko at bonumit dot com
- To: gcc-gnats at gcc dot gnu dot org
- Date: 7 Dec 2002 14:35:00 -0000
- Subject: c++/8858: Gcc "rebinds" template member names.
- Reply-to: eivuokko at bonumit dot com
>Number: 8858
>Category: c++
>Synopsis: Gcc "rebinds" template member names.
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Sat Dec 07 06:36:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: eivuokko@bonumit.com
>Release: gcc-3.2
>Organization:
>Environment:
(also tried with rc version of mingw-gcc 3.2.1)
C:\base\test>g++ -v
Reading specs from c:/devel/mingw/bin/../lib/gcc-lib/mingw32/3.2/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=
mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable
-languages=f77,c++,objc,ada --disable-win32-registry --disable-shared
Thread model: win32
gcc version 3.2 (mingw special 20020817-1)
>Description:
If you have type inside a template, issuing last template-id
as member of it rebinds the template instead of using previous type.
ie
typedef foo::bar<int>::bar<float> baz;
generates same effect as
typedef foo::bar<float> baz;
>How-To-Repeat:
example session, program asserts in unexpected place, it should assert before, for difffrent type.
C:\base\test>g++ gcc_rebind_bug.cpp -o gcc_rebind_bug -Wall && gcc_rebind_bug
Assertion failed: ( IsSame< cons<int, cons<char, cons<double,float> > >, test_ty
pe>::Value ), file gcc_rebind_bug.cpp, line 37
>Fix:
Haven't found one yet, except moving member template outside
the class.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="gcc_rebind_bug.cpp"
Content-Disposition: inline; filename="gcc_rebind_bug.cpp"
#include <cassert>
template<class T_, class U_> class cons {};
template<class L_> class list {
public:
typedef L_ type;
template<class T_> class add :
public ::list< ::cons<T_, L_> > {};
} ;
template<class T1_,class T2_> class IsSame {
public:
enum { Value = false } ;
} ;
template<class T_> class IsSame<T_,T_> {
public:
enum { Value = true } ;
} ;
int main() {
// assure IsSame works
assert(( IsSame<int,int>::Value ));
assert(( IsSame<float,float>::Value ));
assert(( IsSame<cons<int,cons<char,float> >,cons<int,cons<char,float> > >::Value ));
// real test
typedef list<cons<double,float> >::add<char>::add<int>::type test_type;
// this should absolutely fail
assert(( IsSame<
cons<int, cons<double,float> >,
test_type>::Value ));
// and this shouldn't
assert(( IsSame<
cons<int, cons<char, cons<double,float> > >,
test_type>::Value ));
}