Skip to content

Compiler error for requires expression with templated base class member function #84020

Closed
@rath3t

Description

@rath3t

The following code fails to compile with clang trunk and clang 16 (See godbolt link).
The templated member function is not found by clang and therefore the static_assert is triggered.

The struct A inherits from T and therefore the base class member function foo exists, thus the static_assert should not trigger.
It works for non-templated base class member functions though.

struct B {
    template <typename S>
    void foo();

    void bar();
};

template <typename T, typename S>
struct A : T {
    auto foo() {
        static_assert(requires { T::template foo<S>(); });  // fails with clang
        static_assert(requires { T::bar(); });  // works with clang and gcc 12.2
    }
};

int main() {
    A<B, double> a;
    a.foo();
}

Godbolt

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"conceptsC++20 conceptsconfirmedVerified by a second party

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions