[Bug c++/104873] New: Bug in overload resolution for constrained class templates with deduction guides

jgopel at gmail dot com gcc-bugzilla@gcc.gnu.org
Thu Mar 10 21:47:55 GMT 2022


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

            Bug ID: 104873
           Summary: Bug in overload resolution for constrained class
                    templates with deduction guides
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jgopel at gmail dot com
  Target Milestone: ---

Given the following code:

```cpp
template<typename T>
concept C = true;

template<C T>
struct S {
  S(const S&) { ... }
  S(const T&) { ... }
};

// NOTE: The class is constrained, the deduction guide is not
template<typename T>
S(S<T>) -> S<S<T>>;
```

LLVM selects `S(S)` and GCC selects `S(T)`. I believe LLVM is correct here
because the built in deduction guide for `S(S)` is

```cpp
template<C T>
S(const S<T>&) -> S<T>;
```

which is more constrained. I don't believe there's a case where the code
example as-written is intended. I would suggest emitting a warning and using
the built in deduction guide.

Godbolt: https://godbolt.org/z/T79f164nW
LLVM issue suggesting a warning:
https://github.com/llvm/llvm-project/issues/54310
Relevant wording:
- https://eel.is/c++draft/over.match.class.deduct#1.3
- https://eel.is/c++draft/over.match.best#general-2.10


More information about the Gcc-bugs mailing list