<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/112848>112848</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang++17 crashes on valid c++20 code, clang++-18 refuses it with an erroneous error message
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Julien-Blanc-tgcm
      </td>
    </tr>
</table>

<pre>
    I ran into clang++ refusing our code (accepted by gcc), with an error `out-of-line definition of <custom_function> does not match any declaration in <custom_class> ` for clang++-18, and a crash for clang++-17. We are pretty sure our code is valid c++ (and it is accepted by clang++-19).

The error seems related to an out-of-line definition of a template function, inside a variadic template class, with a requirement on the template argument of the function depending on the arguments of the class.

The following code is  a minimal code sample reproducing the issue :

```
#include <type_traits>
#include <iostream>

namespace a
{
namespace details
{
template <typename T, typename... U>
concept Derived = std::conjunction_v<std::is_base_of<U, T>...>;
}
}

struct A
{
    virtual void f() = 0;
};

namespace a
{
template <details::Derived<A> B>
struct S
{
        S(B& b){ b.f(); }
};

struct B: public A
{
    void f() override {
        std::cout << "toto" << std::endl;
        }
};

template<typename... SArgs>
struct Reproduce : protected SArgs..., protected S<SArgs...>
{
        template<details::Derived<SArgs...> T, typename... FArgs>
        void f(FArgs&&... args);
};

}

namespace a
{
template<typename... SArgs>
template<details::Derived<SArgs...> T, typename... FArgs>
void Reproduce<SArgs...>::f(FArgs&&... args)
{
        (std::cout << ... << std::forward<FArgs>(args)) << std::endl;

}
int main()
{
        a::B b;
        a::S<a::B> s(b);
        return 0;
}
```

It seems the namespaces are needed to trigger the crash. However, even if they are not present, the error happens. See https://godbolt.org/z/8K6oKqWv5 and  https://godbolt.org/z/saajbns8d .

clang++-19 correctly accepts the code sample, as well as our code which triggers the same issue.


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVs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