Skip to content

[Clang18][Concepts] Using static data member as concept argument in partially specialized template fails to compile #78101

@kaimfrai

Description

@kaimfrai

The following example compiles with Clang 17 but not in Clang 18 (since approximately 1 week):

template<typename T, typename U, int i>
concept True = true;

template<typename T, int I>
struct Template
{
    static constexpr int i = I;

    friend constexpr auto operator+(True<T, i> auto f)
    {
        return i;
    }
};

template<int I>
struct Template<float, I>
{
    static constexpr int i = I;

    friend constexpr auto operator+(True<float, i> auto f)
    {
        return i;
    }
};

Template<void, 4> f{};

static_assert(+Template<float, 5>{} == 5);

With -std=c++20 on clang 18 I get:

<source>:9:45: error: no member 'i' in 'Template<float, 5>'; it has not yet been instantiated

The error is caused in the static_assert. What's interesting is that it's refering to line 9, which is not the specialization Template<float, 5>.
The error goes away if I remove the variable f, when I don't have a partial specialization, or I use I directly.
This is a problem when I don't want to just use the value of I but the result of a complex expression dependent on I and that result is repeatedly used throughout the specialization, not just 1 function.

Metadata

Metadata

Assignees

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