Skip to content

Clang ignores a constraint in a partial specialization of a class template #58534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Dann239 opened this issue Oct 21, 2022 · 4 comments
Closed
Labels
accepts-invalid clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts

Comments

@Dann239
Copy link

Dann239 commented Oct 21, 2022

I'm trying to create a specialization of the Foo class template that only accepts specializations of the Bar class template as a template argument. However, clang ignores my IsBar<T> constraint and accepts int as a template argument.

template<typename>
struct Foo;

template<typename>
struct Bar {};

template<typename T>
concept IsBar = requires (T t) { [] <typename U> (Bar<U>& c) {} (t); };

template<IsBar T>
struct Foo<T> {
    static void test() {}
};

int main() {
    Foo<Bar<int>>::test(); // OK

    // static_assert(!IsBar<int>);

    // the following line compiles
    // unless i uncomment the static_assert:
    Foo<int>::test(); // this should not compile
}

static_assert'ing !IsBar<int> seems to make it correctly reject int

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Oct 21, 2022
@llvmbot
Copy link
Member

llvmbot commented Oct 21, 2022

@llvm/issue-subscribers-clang-frontend

@usx95
Copy link
Contributor

usx95 commented Jan 11, 2023

This looks more specific to lambda in the simple-requirement

template<typename>
struct Foo;

template<typename T>
concept Add = requires(T t) {
    [](T t) { t++; }(t);
};

template<Add T>
struct Foo<T> {
    static void test() {}
};

int main() {
    Foo<int>::test(); // this should not compile
}

Original code as well as the above gives an assertion failure. It tries to evaluate the dependent lambda without instantiating it properly.
https://godbolt.org/z/fWqbj9Poz

@zyn0217
Copy link
Contributor

zyn0217 commented Mar 7, 2024

This should have been fixed by #83997.
I'll close the PR once the patch gets on godbolt.

@zyn0217
Copy link
Contributor

zyn0217 commented Mar 9, 2024

And here it is: https://godbolt.org/z/474vsh8MP
Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepts-invalid clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts
Projects
Status: Done
Development

No branches or pull requests

6 participants