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++/77502] New: -Wzero-as-null-pointer-constant : misleading/imprecise messages


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

            Bug ID: 77502
           Summary: -Wzero-as-null-pointer-constant : misleading/imprecise
                    messages
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: petschy at gmail dot com
  Target Milestone: ---

Created attachment 39575
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=39575&action=edit
C++ source

g++-7.0.0 -Werror -Wall -Wextra -Wzero-as-null-pointer-constant
20160906-Wzero-as-null-pointer-constant.cpp

20160906-Wzero-as-null-pointer-constant.cpp: In constructor ‘Foo::Foo()’:
20160906-Wzero-as-null-pointer-constant.cpp:10:6: error: zero as null pointer
constant [-Werror=zero-as-null-pointer-constant]
   c(0) // 1
      ^
20160906-Wzero-as-null-pointer-constant.cpp: At global scope:
20160906-Wzero-as-null-pointer-constant.cpp:17:20: error: zero as null pointer
constant [-Werror=zero-as-null-pointer-constant]
  void Fn(char* p = 0); // 2, OK
                    ^
20160906-Wzero-as-null-pointer-constant.cpp: In member function ‘void
TBar<T>::Fn(char*) [with T = int]’:
20160906-Wzero-as-null-pointer-constant.cpp:34:9: error: zero as null pointer
constant [-Werror=zero-as-null-pointer-constant]
  br->Fn(); // 3
         ^
20160906-Wzero-as-null-pointer-constant.cpp: In member function ‘void
TBaz<T>::Fn(char*) [with T = int]’:
20160906-Wzero-as-null-pointer-constant.cpp:35:9: error: zero as null pointer
constant [-Werror=zero-as-null-pointer-constant]
  bz->Fn(); // 4
         ^

The issues:

1) 0 is used instead of nullptr when initializing Foo.a ("a(0)"), but the error
marker is at the end of the initializer list, not at the line of the actual
error.

2) The default argument of Fn() in the non-template Bar class is diagnosed OK

3,4) The default argument of Fn() in the template classes TBar and TBaz is
diagnosed, but the error marker is put at the call site, not at the
declaration. This caused me quite some pondering on the production codebase, as
for a largish templated class hierarchy it's not obvious just by looking at the
call site which fn will be actually called.

Debian Jessie, AMD64
$ g++-7.0.0 -v
Using built-in specs.
COLLECT_GCC=g++-7.0.0
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/7.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --enable-languages=c,c++ --disable-multilib
--program-suffix=-7.0.0 --disable-bootstrap CFLAGS='-O2 -march=native'
CXXFLAGS='-O2 -march=native'
Thread model: posix
gcc version 7.0.0 20160831 (experimental) (GCC)

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