------- Additional Comments From bangerth at dealii dot org 2005-07-18 15:12 ------- I can see how this is happening, and I believe the compiler is correct. Take this slight modification of the code: ----------------------- struct A { A(const char&); operator char(); }; extern A& a1; extern const A& a2; extern const bool b; A f() { return b ? a1 : -a1; // { dg-error "operands to ?: have different types" } return b ? a2 : -a2; // { dg-error "no match for 'operator-'" } } ----------------------------- The point is: a1 is non-const, so for the second argument the compiler uses the conversion to char, then the unary minus on it to get at operator ?: (bool, A&, char) which indeed has different types in the second and third argument. On the other hand, for the second case, a2 is const, so the conversion to char isn't possible, and there is also no unary operator- defined on A. In effect, we get these messages: g/x> /home/bangerth/bin/gcc-4.1-pre/bin/c++ -c x.cc x.cc: In function ‘A f()’: x.cc:11: error: operands to ?: have different types x.cc:12: error: no match for ‘operator-‘ in ‘-a2‘ x.cc:12: note: candidates are: operator-(int) <built-in> To me this all makes a lot of sense. One just has to take into account that const and non-const variables can behave differently. W.
-- What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution| |INVALID http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22549