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

            Bug ID: 77563
           Summary: explicit constructor breaks narrowing conversion
                    overload resolution
           Product: gcc
           Version: 6.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arnetheduck at gmail dot com
  Target Milestone: ---

In the following snippet, an error should be emitted - instead, the compiler
prints a warning and keeps compiling, and simply skips the second call to f (!)
in the resulting executable:

#include <stdint.h>
#include <stdio.h>

struct A {
  A(int32_t a) {}
  A(uint32_t a) {}  // Comment to make it work

  explicit A(int64_t a) {}  // Comment to make it work
};

void f(A a) { printf("hello\n"); }

int main(int, char**) {
  f(2);
  f(3l);
}

/opt/gcc62/bin/g++ -std=gnu++11 explicit.cpp
explicit.cpp: In function ‘int main(int, char**)’:
explicit.cpp:11:6: note:   initializing argument 1 of ‘void f(A)’
 void f(A a) { printf("hello\n"); }
      ^

With either marked constructor commented, compiles correctly and gives the
expected output ("hello" x 2 or ambiguity error).

Reply via email to