Skip to content

[clang] New error in clang21, in-class initializer for static data member is not a constant expression #163517

@lingege321

Description

@lingege321

Hi experts,

I'm updating the clang version from 20 to 21 and see the new error in my project.
The error is introduced from a third-party library and I reduce the code size to a minimum issue.
Please check the compiler-explorer, https://godbolt.org/z/x73rfhWfW

Seems that static member variable must be a constant expression.
However, in this case, type(BOUND+1) is not a constant expression in clang21 but I think it should be considered as a constant expression.

I have some workaround for it but I don't want to do that because it's a third party library.

Is it possible to support this code?

struct Test {
    enum type {
        Type1,
        BOUND
    };
    static const type binding_required = BOUND;
    static const type binding_completed = type(BOUND+1);
    static const type detached = type(binding_completed+1);
    static const type dying = type(detached+1);
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluationinvalidResolved as invalid, i.e. not a bugundefined behaviour

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions