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
707707 initialized, rather than evaluating them as a part of the larger manifestly constant evaluated
708708 expression.
709709- 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).
710711
711712Bug Fixes to AST Handling
712713^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change @@ -7964,6 +7964,11 @@ TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
79647964 // Transform the "then" branch.
79657965 StmtResult Then;
79667966 if (!ConstexprConditionValue || *ConstexprConditionValue) {
7967+ EnterExpressionEvaluationContext Ctx(
7968+ getSema(), Sema::ExpressionEvaluationContext::ImmediateFunctionContext,
7969+ nullptr, Sema::ExpressionEvaluationContextRecord::EK_Other,
7970+ S->isNonNegatedConsteval());
7971+
79677972 Then = getDerived().TransformStmt(S->getThen());
79687973 if (Then.isInvalid())
79697974 return StmtError();
@@ -7978,6 +7983,11 @@ TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
79787983 // Transform the "else" branch.
79797984 StmtResult Else;
79807985 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
7986+ EnterExpressionEvaluationContext Ctx(
7987+ getSema(), Sema::ExpressionEvaluationContext::ImmediateFunctionContext,
7988+ nullptr, Sema::ExpressionEvaluationContextRecord::EK_Other,
7989+ S->isNegatedConsteval());
7990+
79817991 Else = getDerived().TransformStmt(S->getElse());
79827992 if (Else.isInvalid())
79837993 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
420420 // expected-note {{pointer to heap-allocated object}}
421421}
422422#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