llvm / llvm/llvm-project

[19 regression] Wrong overload resolution rules for CTAD in copy-initialization allowing double user-defined conversion

Open
#183,370 5 comments 0 reactions 0 assignees View on GitHub
clang:frontend confirmed regression:19
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Testcase:

```c++
struct Wrap { Wrap(int); };
template struct Class { Class(int); };
Class(Wrap) -> Class;
Class c = 0;
```

This is invalid. The CTAD rules say that we are supposed to form a class whose constructors are the guides of `Class` and try initializing it:

```c++
struct GuideClass {
GuideClass(Wrap);
// ... other constructors ...
};
GuideClass c = 0;
```

But this fails due to [over.best.ics]/4.4, because it would invoke two user-defined conversions (one from `int` to `Wrap` and another from `Wrap` to `GuideClass`). So CTAD should fail here.

Clang 18 and earlier got this right; Clang 19 onwards incorrectly deduces `Class` -> `Class`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.