[PATCH] D145369: Emit const globals with constexpr destructor as constant LLVM values
Eli Friedman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 14 11:43:26 PDT 2023
efriedma added inline comments.
================
Comment at: clang/test/CodeGenCXX/static-init.cpp:181
+#if __cplusplus >= 202002L
+// A const object with constexpr destructor can be emitted as a constant.
+namespace test5 {
----------------
I don't see how this works. For a static local variable, in general, we register the destructor with __cxa_atexit, and the destructor can have arbitrary side-effects. For example:
```
extern void foo();
struct A {
constexpr A() : x(1) {}
constexpr ~A() {if (x) foo();}
int x;
};
const int *f() {
static const A a{};
return &a.x;
}
```
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D145369/new/
https://reviews.llvm.org/D145369
More information about the cfe-commits
mailing list