Skip to content

Constexpr variable with non-trivial constexpr destructor can generate global/exit-time destructor warnings #62436

@pkasting

Description

@pkasting
struct S {
  constexpr ~S() {}  // Intentionally not =default so as to be non-trivial
};
constexpr S s;

Compiling with -std=c++20 -Wglobal-constructors -Wexit-time-destructors triggers both those warnings (see https://godbolt.org/z/9xbKK4Gr1). This seems overly pessimistic; per https://en.cppreference.com/w/cpp/language/constexpr, "If a variable has constant destruction, there is no need to generate machine code in order to call destructor for it, even if its destructor is not trivial.", and indeed there seems to be no generated destructor call here despite the warnings. So I think the warnings are being emitted erroneously.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzergood first issuehttps://github.com/llvm/llvm-project/contribute

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions