errors in handling of non-type template parameters
Ewgenij Gawrilow
gawrilow@math.TU-Berlin.DE
Tue Feb 29 08:33:00 GMT 2000
The following small code pieces expose bugs in the C++ front-end concerning the
handling of non-type template parameters.
System environment as follows:
% uname -a
SunOS sokol 5.7 Generic_106541-08 sun4u sparc SUNW,UltraSPARC-IIi-Engine
% g++ -v
Using builtin specs.
gcc version 2.95.2 19991024 (release)
% cat tmp/gcc-build/config.status
#!/bin/sh
# This file was generated automatically by configure. Do not edit.
# This directory was configured as follows:
.../tmp/gcc-2.95.2/configure --with-gcc-version-trigger=.../tmp/gcc-2.95.2/gcc/version.c --host=sparc-sun-solaris2.6 --enable-shared --enable-version-specific-runtime-libs --enable-languages=c++ --with-gxx-include-dir=/usr/local/include/C++ --norecursion
# using "mh-frag" and "mt-frag"
*********************************************************************************
A template-id with boolean expression not enclosed in parentheses is parsed wrong.
#line 1 "prob1.cc"
template <bool b> class C { };
enum { b1=true, b2=false };
void f()
{
C<b1 && b2> c;
}
Compilation fails with:
prob1.cc: In function `void f()':
prob1.cc:5: `c' undeclared (first use this function)
prob1.cc:5: (Each undeclared identifier is reported only once
prob1.cc:5: for each function it appears in.)
prob1.cc:5: parse error before `;'
If you put parentheses around b1 && b2, everything works fine.
*********************************************************************************
In a bit more complicated context, even parentheses don't prevent the compiler
from crash.
#line 1 "prob2.cc"
struct a { enum { answer=false }; };
template <bool b>
class C {
public:
void f() const;
};
template <bool b>
struct D {
template <class X>
C<(b && X::answer)>
operator() (const X&) const
{
return C<(b && X::answer)>();
}
};
void f()
{
D<true> d;
d(a()).f();
}
ends up with:
prob2.cc: In instantiation of `D<true>':
prob2.cc:21: instantiated from here
prob2.cc:14: Internal compiler error.
*********************************************************************************
With best regards,
Ewgenij Gawrilow
Dept. of Mathematics, Technical University of Berlin
More information about the Gcc-bugs
mailing list