Don't crash if a macro expands to an erroneous expression. (#7652)

For certain kinds of error, clang's parser will succeed but produce an
expression marked as "contains error". Clang's constant evaluator
asserts if given one of those, so return early if we encounter one.
This commit is contained in:
Richard Smith
2026-08-19 00:47:03 +00:00
committed by GitHub
parent d21cc3197f
commit 047555bb1c
2 changed files with 59 additions and 1 deletions
+1 -1
View File
@@ -84,7 +84,7 @@ auto TryEvaluateMacro(Context& context, SemIR::LocId loc_id,
parser.ConsumeAnyToken(true);
}
if (!success) {
if (!success || result_expr->containsErrors()) {
CARBON_DIAGNOSTIC(
InCppMacroEvaluation, Error,
"failed to parse macro Cpp.{0} to a valid constant expression",