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

            Bug ID: 109864
           Summary: excplicit constructor considered during overload
                    resolution leads to ambiguity
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dmatthews at utexas dot edu
  Target Milestone: ---

gcc version:
------------

Using built-in specs.
COLLECT_GCC=/opt/homebrew/opt/gcc/bin/gcc-13
COLLECT_LTO_WRAPPER=/opt/homebrew/Cellar/gcc/13.1.0/bin/../libexec/gcc/aarch64-apple-darwin21/13/lto-wrapper
Target: aarch64-apple-darwin21
Configured with: ../configure --prefix=/opt/homebrew/opt/gcc
--libdir=/opt/homebrew/opt/gcc/lib/gcc/current --disable-nls
--enable-checking=release --with-gcc-major-version-only
--enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-13
--with-gmp=/opt/homebrew/opt/gmp --with-mpfr=/opt/homebrew/opt/mpfr
--with-mpc=/opt/homebrew/opt/libmpc --with-isl=/opt/homebrew/opt/isl
--with-zstd=/opt/homebrew/opt/zstd --with-pkgversion='Homebrew GCC 13.1.0'
--with-bugurl=https://github.com/Homebrew/homebrew-core/issues
--with-system-zlib --build=aarch64-apple-darwin21
--with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.1.0 (Homebrew GCC 13.1.0)

(also tested on all x86_64 versions back to 4.9.x on godbolt.org)

Steps to reproduce:
-------------------

1. Enter the following program in test.cxx:

#include <initializer_list>

struct foo
{
    foo(std::initializer_list<int>) {}
};

struct bar
{
    explicit bar(std::initializer_list<int>) {}
    bar() {}
    void baz(foo) {}
    void baz(bar&&) {}
};

int main()
{
    bar x;
    x.baz({1,2});
}

2. Compile with "gcc test.cxx".

Expected result:
----------------

The program should compile successfully, with a call to bar::baz(foo).

Actual result:
--------------

gcc reports an ambiguity between bar::baz(foo) and bar::baz(bar&&) even though
the latter involves the explicit constructor
bar::bar(std::initializer_list<int>) during an implicit conversion:

test.cxx: In function 'int main()':
test.cxx:19:10: error: call of overloaded 'baz(<brace-enclosed initializer
list>)' is ambiguous
   19 |     x.baz({1,2});
      |     ~~~~~^~~~~~~
test.cxx:12:10: note: candidate: 'void bar::baz(foo)'
   12 |     void baz(foo) {}
      |          ^~~
test.cxx:13:10: note: candidate: 'void bar::baz(bar&&)'
   13 |     void baz(bar&&) {}
      |          ^~~

Reply via email to