Legality of old idiom broken with new parser?

Loren James Rittle rittle@latour.rsch.comm.mot.com
Tue Dec 31 00:00:00 GMT 2002


I enjoy writing optimized solvers (i.e. faster than raw brute force
could obtain) for various pigeon-hole problems.  I recently wrote some
C++ code to solve Rubic's magic square puzzle.  I had to modify the
code to work with the new parser.  This:

  side& north (void) { return (_flipped ? _bottom : _top).north (); }

had to become one of the following:

  side& north (void) { return ((face&) (_flipped ? _bottom : _top)).north (); }

  side& north (void) { return _flipped ? _bottom.north () : _top.north (); }

  side& north (void) { face& f = _flipped ? _bottom : _top; return f.north (); }

to avoid a new error: ``insufficient contextual information to
determine type''.  However, my case is different than all failures in
g++.old-deja/g++.other/overload11.C which generate the error; _bottom
and _top both have the same known type, are members of *this* and,
there is no overloading on north().  Of course, some uses of ?: with
classic C function pointers are explicitly marked as OK in that test.

I can't point to any standard passage that blesses my original use.
Nor will I defend it (or the first replacement).  This message is more
of a "hey, the new parser broke it; should it have done so?"

Here is a compact, stripped, self-contained test case (which appears
not covered in the test suite proper either way):

struct face
{
  int north (void) { return 1; }
};

class tile
{
  face _top, _bottom;
  bool _flipped;
  int north (void) { return (_flipped ? _bottom : _top).north (); }
public:
  tile (face top, face bottom) :
    _top (top), _bottom (bottom), _flipped (false) {}
};

int main ()
{
  new tile (face (), face ());

  return 0;
}

I did not mark line 10 with an error since I don't know if this case
should now fail.  Thanks for the holiday present Mark!

Regards,
Loren



More information about the Gcc-bugs mailing list