[clang] [clang] Reject constexpr-unknown values as constant expressions more consistently (PR #129952)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 6 09:53:12 PST 2025
================
@@ -154,3 +154,26 @@ int g() {
static_assert(f(arr) == 5);
}
}
+
+namespace GH128409 {
+ int &ff();
+ int &x = ff(); // nointerpreter-note {{declared here}}
+ constinit int &z = x; // expected-error {{variable does not have a constant initializer}}
+ // expected-note at -1 {{required by 'constinit' specifier here}}
+ // nointerpreter-note at -2 {{initializer of 'x' is not a constant expression}}
----------------
efriedma-quic wrote:
Both clang and gcc accept the following:
```
int y;
int &r1 = y;
constinit int &r2 = r1;
```
I think that's right, looking at the rules for "potentially-constant" variables?
https://github.com/llvm/llvm-project/pull/129952
More information about the cfe-commits
mailing list