Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ Bug Fixes to C++ Support
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed type checking when a statement expression ends in an l-value of atomic type. (#GH106576)
- Clang now correctly parses ``if constexpr`` expressions in immediate function context. (#GH123524)

Miscellaneous Bug Fixes
^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
14 changes: 12 additions & 2 deletions clang/lib/Parse/ParseExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2203,8 +2203,18 @@ Parser::ParseCXXCondition(StmtResult *InitStmt, SourceLocation Loc,
return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
}

// Parse the expression.
ExprResult Expr = ParseExpression(); // expression
ExprResult Expr;
{
EnterExpressionEvaluationContext Eval(
Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated,
/*LambdaContextDecl=*/nullptr,
/*ExprContext=*/Sema::ExpressionEvaluationContextRecord::EK_Other,
/*ShouldEnter=*/CK == Sema::ConditionKind::ConstexprIf);

// Parse the expression.
Expr = ParseExpression(); // expression
}

if (Expr.isInvalid())
return Sema::ConditionError();

Expand Down
12 changes: 12 additions & 0 deletions clang/test/SemaCXX/constexpr-if.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %clang_cc1 -std=c++20 -verify=cxx20,expected %s
// RUN: %clang_cc1 -std=c++23 -verify=cxx23,expected %s
// RUN: %clang_cc1 -std=c++26 -verify=cxx26,expected %s

// expected-no-diagnostics

namespace GH123524 {
consteval void fn1() {}
void fn2() {
if constexpr (&fn1 != nullptr) { }
}
}