This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/59972] New: -Wunused-value emits inconsistent warnings for unused computed values


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

            Bug ID: 59972
           Summary: -Wunused-value emits inconsistent warnings for unused
                    computed values
           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

Gcc does not emit an unused-value warning for "fn2() ^ 0;", but emits a warning
if this expression is in a comma expression, e.g. "fn2() ^ 0, 0;". This is an
inconsistent behavior.  

I guess the reason for the first case is "fn2() ^ 0 == fn2()". But from the
syntactical perspective, it is an expression and its intention is to output a
value. 

Differently a non-void function call can not only return a value but also have
side effects, and thus the return values can be ignored sometimes. 


$: cat s.c
extern int fn2(void);
int  fn1() {
  fn2() ^ 0;
  return fn2() ^ 0, 0;
}
$: gcc-trunk -Wunused-value -c s.c
s.c: In function âfn1â:
s.c:4:16: warning: value computed is not used [-Wunused-value]
   return fn2() ^ 0, 0;
                ^
$: gcc-trunk --version
gcc-trunk (GCC) 4.9.0 20140127 (experimental)
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$: clang-trunk -Wunused-value -c s.c
s.c:4:16: warning: expression result unused [-Wunused-value]
  return fn2() ^ 0, 0;
         ~~~~~ ^ ~
s.c:3:9: warning: expression result unused [-Wunused-value]
  fn2() ^ 0;
  ~~~~~ ^ ~
2 warnings generated.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]