g++-3.4: static const bool in template struct rejected - why?

Markus Werle numerical.simulation@web.de
Wed Feb 26 10:35:00 GMT 2003


Maybe I am again missing some (new) detail of the C++ standard, so
forgive me if this ain't a bug and enlighten me.

template <class T1, class T2>
struct Is { static const bool SameType = false; };

template <class T>
struct Is<T, T> { static const bool SameType = true; };

#define SAME_TYPE(T1, T2) Is<T1, T2>::SameType

template <class T>
struct Test
  static const bool test1 = SAME_TYPE(double, T);
  static const bool test2 = false;

  static const bool result = test1 || test2;

int main() {
  Test<double> T1;

# g++ GCC-3.4-CannotAppearInConstantExpr.C
GCC-3.4-CannotAppearInConstantExpr.C:16: error: `
   Test<T>::test1' cannot appear in a constant-expression

More information about the Gcc-bugs mailing list