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: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected],
[email protected], [email protected],
[email protected]
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._______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs