This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/22549] Differing error messages depending on thelocality of a variable
- From: "bangerth at dealii dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 18 Jul 2005 15:12:57 -0000
- Subject: [Bug c++/22549] Differing error messages depending on thelocality of a variable
- References: <20050718145831.22549.theodore.papadopoulo@sophia.inria.fr>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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