This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/29280] misleading warning for assignment used as truth construct


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=29280

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2010-02-21 00:38:52         |2016-4-15
                 CC|                            |msebor at gcc dot gnu.org
      Known to fail|                            |4.0.0, 4.5.3, 4.8.3, 4.9.3,
                   |                            |5.3.0, 6.0

--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
It seems like it should be trivial to enhance the warning by adding a note with
the suggestion(s) mentioned in the request.

For reference, the following is what Clang prints:

$ cat t.c && clang -S -Wparentheses t.c
int f (int a, int b)
{
    if (a = b)
        return 1;
    return 2;
}
t.c:3:11: warning: using the result of an assignment as a condition without
      parentheses [-Wparentheses]
    if (a = b)
        ~~^~~
t.c:3:11: note: place parentheses around the assignment to silence this warning
    if (a = b)
          ^
        (    )
t.c:3:11: note: use '==' to turn this assignment into an equality comparison
    if (a = b)
          ^
          ==
1 warning generated.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]