Skip to content

Clang does not realize erroneous overload with inherited constructor #121331

@wangbo15

Description

@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 & 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second party

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions