| Issue |
76359
|
| Summary |
-Wcomma is emmitted for assignments from function return values, even when the result is used as a comparison
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
jpcregan
|
Hello,
My code triggered -Wcomma and upon some research I came across this issue: https://github.com/llvm/llvm-project/issues/57151
It references https://reviews.llvm.org/D3976 which states
> The current whitelisted expressions are increments, decrements, assignments, compound assignments, overloaded versions of these operators, and void returning functions
[Here](https://godbolt.org/z/frh5MorYP) is an example which triggers the warning.
```
#include <stdio.h>
int main (void)
{
int c;
while (c = fgetc(stdin), c != EOF)
{
}
return 0;
}
```
While not strictly a pure assignment, I think the intention is clear and I don't consider it misuse.
Changing the statement to `while ((c = fgetc(stdin)) != EOF)` is functionally identical and does not trigger the warning, but I find it more difficult to read.
Could we add an exception where if the result of a function is used later in the comma it doesn't trigger the warning?
Thanks,
Jordan
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs