egcs-1.1.2 template problem?

nbecker@fred.net nbecker@fred.net
Thu Apr 22 07:39:00 GMT 1999


egcs-1.1.2 i686-pc-linux-gnu.

egcs-1.1.2 accepts this test, which actually makes no sense:

---------------------------------------------------
struct sint_type {
template<int bits>
static int Max() { return ~(0xFFFFFFFFL << (bits-1)); }
template<int bits>
static int Min() { return 0xFFFFFFFFL << (bits-1); }
};

template<int bits, class Signedness>
class Int {
  int val;
public:
  Int& operator= (int x) {
    if (x > Signedness::Max())
      throw range_error ("Int");
    val = x;
  }
};

main () {
  Int<4, sint_type> i;
}

Max is a template member function and we have given no clue how it
should infer the value of bits.
-------------------------------------------

Now if we try to use explicit qualification of Max:
---------------------------------------------------
struct sint_type {
template<int bits>
static int Max() { return ~(0xFFFFFFFFL << (bits-1)); }
template<int bits>
static int Min() { return 0xFFFFFFFFL << (bits-1); }
};

template<int bits, class Signedness>
class Int {
  int val;
public:
  Int& operator= (int x) {
    if (x > Signedness::Max<bits>())
      throw range_error ("Int");
    val = x;
  }
};

main () {
  Int<4, sint_type> i;
}
--------------------------------------------------

we get:
In file included from TestInt.cc:1:
Int.H:18: parse error before `('
Int.H:21: confused by earlier errors, bailing out


More information about the Gcc-bugs mailing list