Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -294,6 +294,7 @@ Bug Fixes to C++ Support
direct-list-initialized from an array is corrected to direct-initialization.
- Clang no longer crashes when a coroutine is declared ``[[noreturn]]``. (#GH127327)
- Clang now uses the parameter location for abbreviated function templates in ``extern "C"``. (#GH46386)
- Clang now correctly parses ``if constexpr`` expressions in immediate function context. (#GH123524)

Improvements to C++ diagnostics
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
12 changes: 10 additions & 2 deletions clang/lib/Parse/ParseExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2203,8 +2203,16 @@ 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.
return 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) { }
}
}