[clang][regression] constraint not satisfied when invoking non type template argument lambda
Example code could be found below or on godbolt. clang 16 and later versions complain that constraints of Base::bar is not satisfied. clang 15, gcc and MSVC all compile fine.
#include <utility>
struct S {
void baz(auto) const& {}
};
template<typename T>
struct Base {
T m_t;
int m_n;
template<auto mem_fn, typename... Args>
void bar(Args&&... args) & requires requires { // clang 16 and later versions: candidate template ignored: constraints not satisfied
mem_fn(m_t, m_n, std::forward<Args>(args)...);
} {
mem_fn(m_t, m_n, std::forward<Args>(args)...);
}
};
template<typename T>
struct Derived: Base<T> {
void foo() & {
[&](auto) { // problem goes away if auto -> int
this->template bar<[](auto& t, auto&&... args) {
t.baz(std::forward<decltype(args)>(args)...);
}>();
}(3);
}
};
void test(Derived<S>& d) {
d.foo();
}
@llvm/issue-subscribers-clang-frontend
Author: Han (wanghan02)
#include <utility>
struct S {
void baz(auto) const& {}
};
template<typename T>
struct Base {
T m_t;
int m_n;
template<auto mem_fn, typename... Args>
void bar(Args&&... args) & requires requires { // clang 16 and later versions: candidate template ignored: constraints not satisfied
mem_fn(m_t, m_n, std::forward<Args>(args)...);
} {
mem_fn(m_t, m_n, std::forward<Args>(args)...);
}
};
template<typename T>
struct Derived: Base<T> {
void foo() & {
[&](auto) { // problem goes away if auto -> int
this->template bar<[](auto& t, auto&&... args) {
t.baz(std::forward<decltype(args)>(args)...);
}>();
}(3);
}
};
void test(Derived<S>& d) {
d.foo();
}
The problem stays if we switch to SFINAE from requires clause. So tag concepts may not be the root cause.
Crashes w/ assertion build
https://godbolt.org/z/r7vzdWxEn
Indeed this goes back to clang-16: https://godbolt.org/z/hY76e7K5M and is a regression
@shafik This issue is no longer reproducible as of Clang 22.1.
Yes this is fixed by #161671