Skip to content

Improve diagnostic of static_assert(requires [...]) #144053

Open
@PJBoy

Description

@PJBoy

When a static assert over a requires expression fails, clang gives no insight as to how the requires expression was evaluated, it just shows the line literatim.

Clang does gives reasonable diagnostics when the same requires expression evaluation causes a constraint failure. I have hope that this mechanism can be leveraged for static_assert too

Testcase https://godbolt.org/z/fnoW3aMM9

#include <concepts>

int g(int);

#if 0
// This diagnostic is reasonable
template<typename T>
    requires requires (T t)
    {
        { g(t) } -> std::same_as<void>;
    }
void f()
{}

#else

template<typename T>
void f()
{
    // This diagnostic is no good
    static_assert(requires (T t)
    {
        { g(t) } -> std::same_as<void>;
    });
}
#endif

void test()
{
    f<int>();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions