This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/66658] New: missing -Wunused-value negating a function result in a comma expression
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 24 Jun 2015 21:28:02 +0000
- Subject: [Bug c/66658] New: missing -Wunused-value negating a function result in a comma expression
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66658
Bug ID: 66658
Summary: missing -Wunused-value negating a function result in a
comma expression
Product: gcc
Version: 5.1.0
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
The -Wunused-value warning is documented to:
Warn whenever a statement computes a result that is explicitly not used.
There are two minor issues here:
1) The following test case shows that GCC misses the opportunity to diagnose
the NOT expression in the first operand of the comma expression:
$ cat /build/tmp/u.c && ~/bin/gcc-5.1.0/bin/g++ -Wunused-value -c -o/dev/null
/build/tmp/u.c
int foo (int, int = 0);
int bar (int a)
{
if (a && !foo (0), 1)
return 1;
return 0;
}
Clang diagnoses this code as one would expect.
The example isn't C++ specific but with default arguments it's easy to
accidentally write "... !foo (0), 1)" when "... foo (0, 1))" is intended.
Having GCC issue a warning will help find these types of mistakes.
2) The documentation is subtly incorrect in that it uses the term "statement"
when what it actually means "expression." If it really meant statement then
expressions such as initializers of function default arguments such as in the
example below would be excluded (when they are not):
int a;
int foo (int, int = 0);
int bar (int, int = (a && !foo (0), 1));