Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions clang/lib/Parse/ParseStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,7 @@ StmtResult Parser::ParseCompoundStatementBody(bool isStmtExpr) {
ParsedStmtContext::Compound |
(isStmtExpr ? ParsedStmtContext::InStmtExpr : ParsedStmtContext());

bool LastIsError = false;
while (!tryParseMisplacedModuleImport() && Tok.isNot(tok::r_brace) &&
Tok.isNot(tok::eof)) {
if (Tok.is(tok::annot_pragma_unused)) {
Expand Down Expand Up @@ -1299,7 +1300,15 @@ StmtResult Parser::ParseCompoundStatementBody(bool isStmtExpr) {

if (R.isUsable())
Stmts.push_back(R.get());
LastIsError = R.isInvalid();
}
// StmtExpr needs to do copy initialization for last statement.
// If last statement is invalid, the last statement in `Stmts` will be
// incorrect. Then the whole compound statement should also be marked as
// invalid to prevent subsequent errors.
if (isStmtExpr && LastIsError && !Stmts.empty())
return StmtError();

// Warn the user that using option `-ffp-eval-method=source` on a
// 32-bit target and feature `sse` disabled, or using
// `pragma clang fp eval_method=source` and feature `sse` disabled, is not
Expand Down
12 changes: 12 additions & 0 deletions clang/test/SemaCXX/gh113468.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s

constexpr int expr() {
if (({
int f;
f = 0;
if (f)
break; // expected-error {{'break' statement not in loop or switch statement}}
}))
return 2;
return 1;
}
Loading