public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/59871] New: No unused value warning for comma expression
@ 2014-01-18  7:57 chengniansun at gmail dot com
  2014-01-18  9:31 ` [Bug c/59871] " jakub at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: chengniansun at gmail dot com @ 2014-01-18  7:57 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59871

            Bug ID: 59871
           Summary: No unused value warning for comma expression
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chengniansun at gmail dot com

I have a return statement with a comma expression -- "return  fn2(), 1, 0;".
Gcc should warn that the "1" in the middle is not used as it does not have any
side effect.  

The following is the detailed instructions to reproduce the issue. 

$: cat s.c
extern int fn2();
int fn1() {
  return  fn2(), 1, 0;
}
$: gcc-trunk -Wall -Wextra -c -std=c99 -pedantic s.c
$: gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/home/chengniansun/tools/gcc-trunk-binaries/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-trunk/configure --enable-languages=c,c++
--disable-multilib --prefix=/home/chengniansun/tools/gcc-trunk-binaries
Thread model: posix
gcc version 4.9.0 20140109 (experimental) (GCC)
$: clang-trunk -Wall -Wextra -c -std=c99 -pedantic s.c
s.c:3:18: warning: expression result unused [-Wunused-value]
  return  fn2(), 1, 0;
                 ^
1 warning generated.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/59871] No unused value warning for comma expression
  2014-01-18  7:57 [Bug c/59871] New: No unused value warning for comma expression chengniansun at gmail dot com
@ 2014-01-18  9:31 ` jakub at gcc dot gnu.org
  2014-01-18 10:08 ` [Bug c/59871] [4.7/4.8/4.9 Regression] " jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-01-18  9:31 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59871

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |mpolacek at gcc dot gnu.org
   Target Milestone|---                         |4.9.0

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Confirmed, for say:
extern int bar ();

void
foo (int *p)
{
  p[0] = (bar (), 1, bar ());
  p[1] = (1, bar ());
  bar (), 1, bar ();
  bar (), 1;
  1, bar ();
}

both g++ and clang warn about all 5 cases, while gcc only about 2 of them.
g++ gives:
pr59871.c:6:27: warning: right operand of comma operator has no effect
[-Wunused-value]
pr59871.c:7:19: warning: left operand of comma operator has no effect
[-Wunused-value]
pr59871.c:8:19: warning: right operand of comma operator has no effect
[-Wunused-value]
pr59871.c:9:12: warning: right operand of comma operator has no effect
[-Wunused-value]
pr59871.c:10:11: warning: left operand of comma operator has no effect
[-Wunused-value]
and gcc only:
pr59871.c:7:12: warning: left-hand operand of comma expression has no effect
[-Wunused-value]
pr59871.c:10:4: warning: left-hand operand of comma expression has no effect
[-Wunused-value]

I'd say we want to follow what C++ FE does.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/59871] [4.7/4.8/4.9 Regression] No unused value warning for comma expression
  2014-01-18  7:57 [Bug c/59871] New: No unused value warning for comma expression chengniansun at gmail dot com
  2014-01-18  9:31 ` [Bug c/59871] " jakub at gcc dot gnu.org
@ 2014-01-18 10:08 ` jakub at gcc dot gnu.org
  2014-01-18 10:15 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-01-18 10:08 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59871

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I'd say easiest would be at the spot where we warn currently about the
left-hand ... check if the left hand operand is a COMPOUND_EXPR, in that case
find the rightmost operand of all the nested COMPOUND_EXPRs and complain about
right-hand operand instead of left-hand.  Perhaps needs some tweaks to get the
locus right.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/59871] [4.7/4.8/4.9 Regression] No unused value warning for comma expression
  2014-01-18  7:57 [Bug c/59871] New: No unused value warning for comma expression chengniansun at gmail dot com
  2014-01-18  9:31 ` [Bug c/59871] " jakub at gcc dot gnu.org
  2014-01-18 10:08 ` [Bug c/59871] [4.7/4.8/4.9 Regression] " jakub at gcc dot gnu.org
@ 2014-01-18 10:15 ` jakub at gcc dot gnu.org
  2014-01-18 11:07 ` mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-01-18 10:15 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59871

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
And similarly in emit_side_effect_warnings, if there are TREE_SIDE_EFFECTS, but
the expr is COMPOUND_EXPR, find the rightmost operand of the nested
COMPOUND_EXPRs and if it doesn't have TREE_SIDE_EFFECTS, warn similarly.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/59871] [4.7/4.8/4.9 Regression] No unused value warning for comma expression
  2014-01-18  7:57 [Bug c/59871] New: No unused value warning for comma expression chengniansun at gmail dot com
                   ` (2 preceding siblings ...)
  2014-01-18 10:15 ` jakub at gcc dot gnu.org
@ 2014-01-18 11:07 ` mpolacek at gcc dot gnu.org
  2014-01-23 19:05 ` mpolacek at gcc dot gnu.org
  2014-01-23 19:07 ` mpolacek at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-01-18 11:07 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59871

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org

--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Thanks.  Mine for now then.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/59871] [4.7/4.8/4.9 Regression] No unused value warning for comma expression
  2014-01-18  7:57 [Bug c/59871] New: No unused value warning for comma expression chengniansun at gmail dot com
                   ` (3 preceding siblings ...)
  2014-01-18 11:07 ` mpolacek at gcc dot gnu.org
@ 2014-01-23 19:05 ` mpolacek at gcc dot gnu.org
  2014-01-23 19:07 ` mpolacek at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-01-23 19:05 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59871

--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Author: mpolacek
Date: Thu Jan 23 19:04:29 2014
New Revision: 207002

URL: http://gcc.gnu.org/viewcvs?rev=207002&root=gcc&view=rev
Log:
    PR c/59871
c/
    * c-typeck.c (build_compound_expr): Warn even for right-hand operand
    of a comma expression.
    (emit_side_effect_warnings): Likewise.
libdecnumber/
    * decNumberLocal.h (UBFROMUS, UBFROMUI): Remove last argument.
testsuite/
    * gcc.dg/20020220-2.c: Adjust dg-warning message.
    * gcc.dg/pr59871.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr59871.c
Modified:
    trunk/gcc/c/ChangeLog
    trunk/gcc/c/c-typeck.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/20020220-2.c
    trunk/libdecnumber/ChangeLog
    trunk/libdecnumber/decNumberLocal.h


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c/59871] [4.7/4.8/4.9 Regression] No unused value warning for comma expression
  2014-01-18  7:57 [Bug c/59871] New: No unused value warning for comma expression chengniansun at gmail dot com
                   ` (4 preceding siblings ...)
  2014-01-23 19:05 ` mpolacek at gcc dot gnu.org
@ 2014-01-23 19:07 ` mpolacek at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-01-23 19:07 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59871

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #8 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-01-23 19:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-18  7:57 [Bug c/59871] New: No unused value warning for comma expression chengniansun at gmail dot com
2014-01-18  9:31 ` [Bug c/59871] " jakub at gcc dot gnu.org
2014-01-18 10:08 ` [Bug c/59871] [4.7/4.8/4.9 Regression] " jakub at gcc dot gnu.org
2014-01-18 10:15 ` jakub at gcc dot gnu.org
2014-01-18 11:07 ` mpolacek at gcc dot gnu.org
2014-01-23 19:05 ` mpolacek at gcc dot gnu.org
2014-01-23 19:07 ` mpolacek at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).