[Bug c++/25689] missed diagnostic about assignment used as truth value.
manu at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sun Oct 12 13:09:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25689
Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed|2006-01-06 12:32:23 |2014-10-12
--- Comment #2 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
A simpler testcase:
struct Var {
operator int() const;
Var& operator = (int);
};
void foo(Var var)
{
if (var = 0) {} // we should warn
if (var.operator=(0)) {} // we should NOT warn
}
Clang prints:
pr25689.C:8:11: warning: using the result of an assignment as a condition
without parentheses [-Wparentheses]
if (var = 0) {} // if (var.operator=(0))
~~~~^~~
pr25689.C:8:11: note: place parentheses around the assignment to silence this
warning
if (var = 0) {} // if (var.operator=(0))
^
( )
pr25689.C:8:11: note: use '==' to turn this assignment into an equality
comparison
if (var = 0) {} // if (var.operator=(0))
^
==
More information about the Gcc-bugs
mailing list