[Bug c++/77563] explicit constructor breaks narrowing conversion overload resolution

arnetheduck at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Sep 12 09:44:00 GMT 2016


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

--- Comment #1 from Jacek Sieka <arnetheduck at gmail dot com> ---
gcc 5.3.0 gives a different error - looks odd though, no initializer list in
sight:

/opt/gcc53/bin/g++ -std=gnu++11 explicit.cpp
explicit.cpp: In function ‘int main(int, char**)’:
explicit.cpp:15:7: error: converting to ‘A’ from initializer list would use
explicit constructor ‘A::A(int64_t)’
   f(3l);
       ^
explicit.cpp:11:6: note:   initializing argument 1 of ‘void f(A)’
 void f(A a) { printf("hello\n"); }
      ^
clang++ 3.8 complains about ambiguity:

clang++ -std=gnu++11 explicit.cpp
explicit.cpp:15:5: error: conversion from 'long' to 'A' is ambiguous
  f(3l);
    ^~
explicit.cpp:5:3: note: candidate constructor
  A(int32_t a) {}
  ^
explicit.cpp:6:3: note: candidate constructor
  A(uint32_t a) {}
  ^
explicit.cpp:11:10: note: passing argument to parameter 'a' here
void f(A a) { printf("hello\n"); }


More information about the Gcc-bugs mailing list