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++/59704] New: Wrong overload chosen, compiler errornously thinks non-constant zero expression is implicitly castable to null pointer


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

            Bug ID: 59704
           Summary: Wrong overload chosen, compiler errornously thinks
                    non-constant zero expression is implicitly castable to
                    null pointer
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ambrus at math dot bme.hu

Created attachment 31759
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31759&action=edit
preprocessed C++ source file

Gcc gives an error compiling the attached C++ file, despite that the code is
valid and should compile.  

The error message claims that I am trying to call the first (non-vararg)
overload of the function covl, which is deleted.  In reality, the code should
be calling the second (vararg) overload of the function.  The second argument
in the call is an integral typed expression that is not a constant expression,
and so it cannot be implicitly converted to a pointer and cannot match the
parameter in the first overload of the function covl.  Although the expression
(v - v) would always have a value of zero in this context, the expression
contains lvalue-to-rvalue conversion of a non-const variable, which makes this
expression not count as a constant expression according to tha language rules. 
Thus, the call should fall back to use the second overload of the function
covl, which it does match.

I am using gcc 4.8.1 compiled from vanilla sources, on a linux-x86_64 system. 
The command line is

    g++ -v -c -std=c++11 -x c++-cpp-output zerocast.ii

The preprocessed C++ source file should be attached to this ticket.  Below you
can see the full output of g++, including the configuration options.



$ cat zerocast.ii
# 1 "zerocast.cxx"
# 1 "<command-line>"
# 1 "zerocast.cxx"

void covl(int d, void *v) = delete;
void covl(int d, ...);
void bspr(unsigned v) {
 covl(0, v - v);
}
$ g++ -v -c -std=c++11 -x c++-cpp-output zerocast.ii
Using built-in specs.
COLLECT_GCC=g++
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.8.1/configure --prefix=/usr/local/gcc481
-with-gmp=/usr/local -with-mpfr=/usr/local -with-mpc=/usr/local
--enable-languages=c,c++,fortran
Thread model: posix
gcc version 4.8.1 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-c' '-std=c++11' '-shared-libgcc' '-mtune=generic'
'-march=x86-64'
 /usr/local/gcc481/libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/cc1plus
-fpreprocessed zerocast.ii -quiet -dumpbase zerocast.ii -mtune=generic
-march=x86-64 -auxbase zerocast -std=c++11 -version -o /tmp/ccgVThJQ.s
GNU C++ (GCC) version 4.8.1 (x86_64-unknown-linux-gnu)
    compiled by GNU C version 4.8.1, GMP version 5.0.1, MPFR version 3.0.0-p3,
MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=127409
GNU C++ (GCC) version 4.8.1 (x86_64-unknown-linux-gnu)
    compiled by GNU C version 4.8.1, GMP version 5.0.1, MPFR version 3.0.0-p3,
MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=127409
Compiler executable checksum: 47191b782ec6877222820ebb50c2fe12
zerocast.cxx: In function âvoid bspr(unsigned int)â:
zerocast.cxx:5:15: error: use of deleted function âvoid covl(int, void*)â
  covl(0, v - v);
               ^
zerocast.cxx:2:6: error: declared here
 void covl(int d, void *v) = delete;
      ^
$

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