File tree Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -1808,12 +1808,24 @@ struct CounterCoverageMappingBuilder
1808
1808
}
1809
1809
}
1810
1810
1811
+ private:
1812
+ static bool evaluateConstantCondition (const Expr *Condition) {
1813
+ if (const auto *Expr = dyn_cast<ConstantExpr>(Condition))
1814
+ return Expr->getResultAsAPSInt ().getExtValue ();
1815
+
1816
+ if (const auto *Expr = dyn_cast<ExprWithCleanups>(Condition))
1817
+ return evaluateConstantCondition (Expr->getSubExpr ()); // recursion
1818
+
1819
+ assert (false && " Unexpected node in 'if constexpr' condition" );
1820
+ return false ;
1821
+ }
1822
+
1823
+ public:
1811
1824
void coverIfConstexpr (const IfStmt *S) {
1812
1825
assert (S->isConstexpr ());
1813
1826
1814
1827
// evaluate constant condition...
1815
- const auto *E = cast<ConstantExpr>(S->getCond ());
1816
- const bool isTrue = E->getResultAsAPSInt ().getExtValue ();
1828
+ const bool isTrue = evaluateConstantCondition (S->getCond ());
1817
1829
1818
1830
extendRegion (S);
1819
1831
Original file line number Diff line number Diff line change @@ -234,6 +234,35 @@ constexpr int check_macro_consteval_if_skipped(int i) { // CHECK-NEXT: [[@LINE
234
234
return i;
235
235
}
236
236
237
+ struct false_value {
238
+ constexpr operator bool () {
239
+ return false ;
240
+ }
241
+ };
242
+
243
+ template <typename > struct dependable_false_value {
244
+ constexpr operator bool () {
245
+ return false ;
246
+ }
247
+ };
248
+
249
+ // GH-80285
250
+ void should_not_crash () {
251
+ if constexpr (false_value{}) { };
252
+ }
253
+
254
+ template <typename > void should_not_crash_dependable () {
255
+ if constexpr (dependable_false_value<int >{}) { };
256
+ }
257
+
258
+ void should_not_crash_with_template_instance () {
259
+ should_not_crash_dependable<int >();
260
+ }
261
+
262
+ void should_not_crash_with_requires_expr () {
263
+ if constexpr (requires {42 ;}) { };
264
+ }
265
+
237
266
int instantiate_consteval (int i) {
238
267
i *= check_consteval_with_else_discarded_then (i);
239
268
i *= check_notconsteval_with_else_discarded_else (i);
You can’t perform that action at this time.
0 commit comments