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/79074] New: -Waddress difference between C and C++ with (T*)0


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79074

            Bug ID: 79074
           Summary: -Waddress difference between C and C++ with (T*)0
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The regression test added for bug 47931 fails in C++ mode because C++ warns on
pointless comparisons with a null pointer even if it's not a null pointer
constant (e.g., (int*)0).  Fixing the failure by adding the appropriate
dg-warning directive makes the test fail in C (where it runs with -Wc++-compat)
because C only warns only for comparisons with a null pointer constant.  It
seems that the two front ends should warn consistently for same expressions. 
If there's some reason not to warn in C when the null pointer doesn't strictly
meet the requirements of a null pointer constant then it should warn with
-Wc++-compat for compatibility.

$ (set -x; cat t.c && for l in c c++; do /build/gcc-svn/gcc/xgcc -B
/build/gcc-svn/gcc -S -Waddress -x$l t.c; done)
+ cat t.c
int f (int i) { return &i != (void *) 0; }

int g (int i) { return &i != (int *) 0; }

+ for l in c c++
+ /build/gcc-svn/gcc/xgcc -B /build/gcc-svn/gcc -S -Waddress -xc t.c
t.c: In function ‘f’:
t.c:1:27: warning: the comparison will always evaluate as ‘true’ for the
address of ‘i’ will never be NULL [-Waddress]
 int f (int i) { return &i != (void *) 0; }
                           ^~
+ for l in c c++
+ /build/gcc-svn/gcc/xgcc -B /build/gcc-svn/gcc -S -Waddress -xc++ t.c
t.c: In function ‘int f(int)’:
t.c:1:27: warning: the address of ‘i’ will never be NULL [-Waddress]
 int f (int i) { return &i != (void *) 0; }
                        ~~~^~~~~~~~~~~~~
t.c: In function ‘int g(int)’:
t.c:3:27: warning: the address of ‘i’ will never be NULL [-Waddress]
 int g (int i) { return &i != (int *) 0; }
                        ~~~^~~~~~~~~~~~

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