File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -707,6 +707,7 @@ Bug Fixes to C++ Support
707
707
initialized, rather than evaluating them as a part of the larger manifestly constant evaluated
708
708
expression.
709
709
- Fix a bug in access control checking due to dealyed checking of friend declaration. Fixes (#GH12361).
710
+ - Correctly treat the compound statement of an ``if consteval `` as an immediate context. Fixes (#GH91509).
710
711
711
712
Bug Fixes to AST Handling
712
713
^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change @@ -7964,6 +7964,11 @@ TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
7964
7964
// Transform the "then" branch.
7965
7965
StmtResult Then;
7966
7966
if (!ConstexprConditionValue || *ConstexprConditionValue) {
7967
+ EnterExpressionEvaluationContext Ctx(
7968
+ getSema(), Sema::ExpressionEvaluationContext::ImmediateFunctionContext,
7969
+ nullptr, Sema::ExpressionEvaluationContextRecord::EK_Other,
7970
+ S->isNonNegatedConsteval());
7971
+
7967
7972
Then = getDerived().TransformStmt(S->getThen());
7968
7973
if (Then.isInvalid())
7969
7974
return StmtError();
@@ -7978,6 +7983,11 @@ TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
7978
7983
// Transform the "else" branch.
7979
7984
StmtResult Else;
7980
7985
if (!ConstexprConditionValue || !*ConstexprConditionValue) {
7986
+ EnterExpressionEvaluationContext Ctx(
7987
+ getSema(), Sema::ExpressionEvaluationContext::ImmediateFunctionContext,
7988
+ nullptr, Sema::ExpressionEvaluationContextRecord::EK_Other,
7989
+ S->isNegatedConsteval());
7990
+
7981
7991
Else = getDerived().TransformStmt(S->getElse());
7982
7992
if (Else.isInvalid())
7983
7993
return StmtError();
Original file line number Diff line number Diff line change @@ -420,3 +420,29 @@ int f = *fn().value + fn2(); // expected-error {{call to consteval function 'lv
420
420
// expected-note {{pointer to heap-allocated object}}
421
421
}
422
422
#endif
423
+
424
+
425
+ #if __cplusplus >= 202302L
426
+
427
+ namespace GH91509 {
428
+
429
+ consteval int f (int ) { return 0 ; }
430
+
431
+ template <typename T>
432
+ constexpr int g (int x) {
433
+ if consteval {
434
+ return f (x);
435
+ }
436
+ if !consteval {}
437
+ else {
438
+ return f (x);
439
+ }
440
+ return 1 ;
441
+ }
442
+
443
+ int h (int x) {
444
+ return g<void >(x);
445
+ }
446
+ }
447
+
448
+ #endif
You can’t perform that action at this time.
0 commit comments