Skip to content

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

Closed
@Dann239

Description

@Dann239

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions