llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang][regression] constraint not satisfied when invoking non type template argument lambda

Open wanghan02 opened this issue 2 years ago • 6 comments

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();
}

wanghan02 avatar Oct 30 '24 15:10 wanghan02

@llvm/issue-subscribers-clang-frontend

Author: Han (wanghan02)

Example code could be found below or on [godbolt](https://godbolt.org/z/KjfqcaxEq). clang 16 and later versions complain that constraints of Base::bar is not satisfied. clang 15, gcc and MSVC all compile fine.
#include &lt;utility&gt;

struct S {
    void baz(auto) const&amp; {}
};

template&lt;typename T&gt;
struct Base {
    T m_t;
    int m_n;

    template&lt;auto mem_fn, typename... Args&gt;
    void bar(Args&amp;&amp;... args) &amp; requires requires { // clang 16 and later versions: candidate template ignored: constraints not satisfied
        mem_fn(m_t, m_n, std::forward&lt;Args&gt;(args)...);
    } {
        mem_fn(m_t, m_n, std::forward&lt;Args&gt;(args)...);
    }
};

template&lt;typename T&gt;
struct Derived: Base&lt;T&gt; {
    void foo() &amp; {
        [&amp;](auto) { // problem goes away if auto -&gt; int
            this-&gt;template bar&lt;[](auto&amp; t, auto&amp;&amp;... args) {
                t.baz(std::forward&lt;decltype(args)&gt;(args)...);
            }&gt;();
        }(3);
    }
};

void test(Derived&lt;S&gt;&amp; d) {
    d.foo();
}

llvmbot avatar Oct 30 '24 15:10 llvmbot

The problem stays if we switch to SFINAE from requires clause. So tag concepts may not be the root cause.

wanghan02 avatar Oct 30 '24 15:10 wanghan02

Crashes w/ assertion build

https://godbolt.org/z/r7vzdWxEn

zyn0217 avatar Oct 31 '24 03:10 zyn0217

Indeed this goes back to clang-16: https://godbolt.org/z/hY76e7K5M and is a regression

shafik avatar Nov 15 '24 23:11 shafik

@shafik This issue is no longer reproducible as of Clang 22.1.

eiytoq avatar May 08 '26 03:05 eiytoq

Yes this is fixed by #161671

zyn0217 avatar May 08 '26 06:05 zyn0217