You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[clang] Remove separate evaluation step for static class member init. (#142713)
We already evaluate the initializers for all global variables, as
required by the standard. Leverage that evaluation instead of trying to
separately validate static class members.
This has a few benefits:
- Improved diagnostics; we now get notes explaining what failed to
evaluate.
- Improved correctness: is_constant_evaluated is handled correctly.
The behavior follows the proposed resolution for CWG1721.
Fixes#88462. Fixes#99680.
Copy file name to clipboardExpand all lines: clang/test/SemaCXX/builtin-is-constant-evaluated.cpp
+14Lines changed: 14 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -154,3 +154,17 @@ namespace narrowing {
154
154
// expected-note {{insert an explicit cast to silence this issue}}
155
155
}
156
156
}
157
+
158
+
structGH99680 {
159
+
staticconstint x1 = 1/(1-__builtin_is_constant_evaluated()); // expected-error {{in-class initializer for static data member is not a constant expression}} \
staticconstfloat x3 = 1/(1-__builtin_is_constant_evaluated()); // expected-error {{in-class initializer for static data member of type 'const float' requires 'constexpr' specifier}} \
164
+
// expected-note {{add 'constexpr'}} \
165
+
// expected-error {{in-class initializer for static data member is not a constant expression}} \
166
+
// expected-note {{division by zero}}
167
+
staticconstfloat x4 = __builtin_is_constant_evaluated(); // expected-error {{in-class initializer for static data member of type 'const float' requires 'constexpr' specifier}} \
0 commit comments