[clang] [clang] Remove separate evaluation step for static class member init. (PR #142713)

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 10 11:01:57 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}}
----------------
zygoloid wrote:

Aha, the resolution for [CWG1721](https://cplusplus.github.io/CWG/issues/1721.html) (not yet resolved but in "review" state, which means CWG thinks the wording is ready for final review before resolution) changes the rule to check whether the variable is constant-initialized (thanks @t3nsor for pointing this out!). So this PR is implementing the proposed resolution of that issue.

https://github.com/llvm/llvm-project/pull/142713


More information about the cfe-commits mailing list