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

             Bug #: 53301
           Summary: Spurious -Wzero-as-null-pointer-constant with
                    reference arguments
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: ll...@randombit.net
              Host: x86_64-unknown-linux-gnu
            Target: x86_64-unknown-linux-gnu
             Build: x86_64-unknown-linux-gnu


The following causes a warning under -Wzero-as-null-pointer-constant:

"""
class x { public: x(int v) {} };

void foo(const x& = 0);
"""

wnull.cpp:4:22: warning: zero as null pointer constant
[-Wzero-as-null-pointer-constant]
 void foo(const x& = 0);

The warning is avoided if the argument is passed as a non-reference type or if
the default argument is `x(0)`. Likely the reference type is being treated
identically to a pointer type even though in this case the value is used to
initialize the underlying type, not the reference.

$ g++-4.8.0-r187195 -v
Using built-in specs.
COLLECT_GCC=/usr/local/gcc-4.8.0-r187195/bin/g++-4.8.0-r187195
COLLECT_LTO_WRAPPER=/usr/local/gcc-4.8.0-r187195/libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-svn/configure --prefix=/usr/local/gcc-4.8.0-r187195
--enable-languages=c,c++ --program-suffix=-4.8.0-r187195
Thread model: posix
gcc version 4.8.0 20120505 (experimental) (GCC)

Reply via email to