Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang does not realize erroneous overload with inherited constructor #121331

Open
wangbo15 opened this issue Dec 30, 2024 · 3 comments
Open

Clang does not realize erroneous overload with inherited constructor #121331

wangbo15 opened this issue Dec 30, 2024 · 3 comments
Labels
c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party

Comments

@wangbo15
Copy link

The following code is rejected by GCC, MSVC, and EDG but accepted by Clang:

struct C
{
    C(int = 1){}
};

struct D
{
  D (C);
};

struct A : D
{
  A (const C & n) : D (C{100}) {}
  using D:: D;
};

int main(){
    A a=C{};
}

As the diagnostic shows, the user-defined ctor A(const C & n) of class A has the same parameter list as the inherited ctor, which leads to ambiguity:

<source>: In function 'int main()':
<source>:18:9: error: conversion from 'C' to 'A' is ambiguous
   18 |     A a=C{};
      |         ^~~
<source>:18:9: note: there are 6 candidates
<source>:8:3: note: candidate 1: 'D::D(C)'
    8 |   D (C);
      |   ^
<source>:14:13: note: inherited here
   14 |   using D:: D;
      |             ^
<source>:13:3: note: candidate 2: 'A::A(const C&)'
   13 |   A (const C & n) : D (C{100}) {}

Please see https://godbolt.org/z/vG9cqvMbc

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Dec 30, 2024
@hstk30-hw hstk30-hw added the c++ label Dec 30, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 30, 2024

@llvm/issue-subscribers-c-1

Author: Bo Wang (wangbo15)

The following code is rejected by GCC, MSVC, and EDG but accepted by Clang:
struct C
{
    C(int = 1){}
};

struct D
{
  D (C);
};

struct A : D
{
  A (const C &amp; n) : D (C{100}) {}
  using D:: D;
};

int main(){
    A a=C{};
}

As the diagnostic shows, the user-defined ctor A(const C &amp; n) of class A has the same parameter list as the inherited ctor, which leads to ambiguity:

&lt;source&gt;: In function 'int main()':
&lt;source&gt;:18:9: error: conversion from 'C' to 'A' is ambiguous
   18 |     A a=C{};
      |         ^~~
&lt;source&gt;:18:9: note: there are 6 candidates
&lt;source&gt;:8:3: note: candidate 1: 'D::D(C)'
    8 |   D (C);
      |   ^
&lt;source&gt;:14:13: note: inherited here
   14 |   using D:: D;
      |             ^
&lt;source&gt;:13:3: note: candidate 2: 'A::A(const C&amp;)'
   13 |   A (const C &amp; n) : D (C{100}) {}

Please see https://godbolt.org/z/vG9cqvMbc

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed clang Clang issues not falling into any other category labels Dec 30, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 30, 2024

@llvm/issue-subscribers-clang-frontend

Author: Bo Wang (wangbo15)

The following code is rejected by GCC, MSVC, and EDG but accepted by Clang:
struct C
{
    C(int = 1){}
};

struct D
{
  D (C);
};

struct A : D
{
  A (const C &amp; n) : D (C{100}) {}
  using D:: D;
};

int main(){
    A a=C{};
}

As the diagnostic shows, the user-defined ctor A(const C &amp; n) of class A has the same parameter list as the inherited ctor, which leads to ambiguity:

&lt;source&gt;: In function 'int main()':
&lt;source&gt;:18:9: error: conversion from 'C' to 'A' is ambiguous
   18 |     A a=C{};
      |         ^~~
&lt;source&gt;:18:9: note: there are 6 candidates
&lt;source&gt;:8:3: note: candidate 1: 'D::D(C)'
    8 |   D (C);
      |   ^
&lt;source&gt;:14:13: note: inherited here
   14 |   using D:: D;
      |             ^
&lt;source&gt;:13:3: note: candidate 2: 'A::A(const C&amp;)'
   13 |   A (const C &amp; n) : D (C{100}) {}

Please see https://godbolt.org/z/vG9cqvMbc

@zygoloid
Copy link
Collaborator

It looks like Clang implements a pre-standard version of [over.match.best.general]/2.7 without the "all parameters have the same type" portion. There's a FIXME for this here.

@shafik shafik added the confirmed Verified by a second party label Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party
Projects
None yet
Development

No branches or pull requests

6 participants