Daniel M. Katz c4724f6038
Fix assertion failure during conversion function overload resolution. (#98671)
When clang is built with assertions, an otherwise silent (and seemingly
innocuous) assertion failure from `SemaConcept.cpp` is triggered by the
following program:

```cpp
struct S {
  operator int();
  template <typename T> operator T();
};

constexpr auto r = &S::operator int;
```

The function in question compares the "constrained-ness" of `S::operator
int` and `S::operator T<int>`; the template kind of the former is
`TK_NonTemplate`, whereas the template kind of the later is
`TK_FunctionTemplateSpecialization`. The later kind is not "expected" by
the function, thus the assertion-failure.
2024-08-12 13:11:21 -04:00

29 lines
741 B
C++

// RUN: %clang_cc1 -std=c++20 -fsyntax-only %s -verify
struct S1 {
operator int();
template <typename T>
operator T();
};
// Ensure that no assertion is raised when overload resolution fails while
// choosing between an operator function template and an operator function.
constexpr auto r = &S1::operator int;
// expected-error@-1 {{initializer of type '<overloaded function type>'}}
template <typename T>
struct S2 {
template <typename U=T>
S2(U={}) requires (sizeof(T) > 0) {}
// expected-note@-1 {{candidate constructor}}
template <typename U=T>
S2(U={}) requires (true) {}
// expected-note@-1 {{candidate constructor}}
};
S2<int> s; // expected-error {{call to constructor of 'S2<int>' is ambiguous}}