[clang] [clang] Remove separate evaluation step for static class member init. (PR #142713)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 5 13:44:16 PDT 2025
================
@@ -143,3 +143,8 @@ namespace fold_initializer {
const float A::f = __builtin_is_constant_evaluated();
static_assert(fold(A::f == 1.0f));
}
+
+struct GH99680 {
+ static const int x = 1/(1-__builtin_is_constant_evaluated()); // expected-error {{in-class initializer for static data member is not a constant expression}} \
+ // expected-note {{division by zero}}
----------------
efriedma-quic wrote:
This example is illegal for the same reason you can't write `int f(); struct X { static const int x = f(); };`. Normally static data members aren't allowed to have initializers at all if they're not `inline`. But there's a very narrow carveout in [class.static.data]p4: if the type is a `const` non-`volatile` integer type, it's allowed if the initializer is constant expression.
https://github.com/llvm/llvm-project/pull/142713
More information about the cfe-commits
mailing list