[llvm-bugs] [Bug 47364] New: Missing -Wparentheses warning for assignment withing assert()

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Aug 31 05:34:04 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47364

            Bug ID: 47364
           Summary: Missing -Wparentheses warning for assignment withing
                    assert()
           Product: clang
           Version: 10.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mpg at elzevir.fr
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Hi,

Consider the following example:

#include <assert.h>

extern int foo(void);

int main(void) {
    int ret = foo();
    assert(ret = 0); // oops
}

Compiled with `clang -Weverything -Werror -std=c99 -pedantic -c` (Clang
version: 10.0.0-4ubuntu1) it doesn't produce any warning.

The line marked "oops" is an actual typo I made in a project, and I would have
been grateful if Clang had given me a warning for it.

In fact, considering Clang warns about `if(ret = 0)` I was expecting to get a
warning for the same thing in the context of `assert()` too. I understand from
reading other bugs that `assert()` gets special treatment from `-Wparentheses`
to avoid warning on common idioms such as `assert(x && "failure message");`,
but I hope there's a way to still accept those idioms while warning about
relatively-obvious typos such as the above.

Fwiw, GCC gives the kind of warning I would expect here:

foo.c:7:12: warning: suggest parentheses around assignment used as truth value
[-Wparentheses]

Please consider making Clang produce a similar warning in this instance.

Thanks,
Manuel.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200831/9c147110/attachment-0001.html>


More information about the llvm-bugs mailing list