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
2 changes: 1 addition & 1 deletion clang/lib/Parse/ParseStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ StmtResult Parser::ParseCaseStatement(ParsedStmtContext StmtCtx,
return StmtError();
}
} else {
LHS = Expr;
LHS = Actions.ActOnCaseExpr(CaseLoc, Expr);
MissingCase = false;
}

Expand Down
6 changes: 6 additions & 0 deletions clang/test/SemaCXX/constant-expression-cxx14.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1450,3 +1450,9 @@ namespace GH149500 {
unsigned int * p = &(*(unsigned int *)0x400);
static const void *q = &(*(const struct sysrq_key_op *)0);
}

constexpr bool missingCase() {
switch (1) {
1u: return false; // expected-error {{expected 'case' keyword before expression}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused; we already emit this diagnostic today without your changes: https://godbolt.org/z/4379s9zGf

You mention this is about getting the usual conversions to happen, but those only need to happen for well-formed code, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not about the diagnostic, it's about clang crashing in constant evaluation because the type of the case stmt expression is wrong: #165555 (the second example further down).

I don't know if the conversions only need to happen for well-formed code or not. If not, we should instead mark the case stmt as having errors I guess, but just letting it through like that trips up a couple of places

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see now that my godbolt link does show the issue with an asserts build, that makes more sense now. Thank you!

}
}