Skip to content

clang++: wrong error about non-const member #137619

Open
@stsp

Description

@stsp
class A {
    static const char *aaa = "aaa";
};

clang++:

cstr.cpp:2:24: error: non-const static data member must be initialized out of line
    2 |     static const char *aaa = "aaa";

This error is absolutely wrong
and misleading. I had to use gcc
to get a clue:

g++:

cstr.cpp:2:24: error: ‘constexpr’ needed for in-class initialization of static data member ‘const char* A::aaa’ of non-integral type [-fpermissive]
    2 |     static const char *aaa = "aaa";

Perfectly clear and valid msg.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerquality-of-implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions