Skip to content

Reference argument specified as template can't be used in constexpr if #129573

@abellgithub

Description

@abellgithub

Perhaps a duplicate of #63139

The following fails to compile with 19.1.0 and current trunk. It works if the argument is a value type instead of reference. Works with GCC.

class Foo
{
public:
    constexpr static bool foo = true;
};

template <typename T>
int func(T& t)
{
    if constexpr (t.foo)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

int main()
{
    Foo f;

    int i = func(f);
    return i;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions