diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -706,6 +706,12 @@ llvm_unreachable("conversion functions are permitted"); } } SwitchDiagnoser(Cond); + // The TypoExpr might be corrected to a non-intergral-or-enum type in the + // later stage without the proper type check, which is invalid for switch + // condition, so we fail the check here (this would avoid emitting incorrect + // fixit). + if (llvm::isa(Cond)) + return ExprError(); ExprResult CondResult = PerformContextualImplicitConversion(SwitchLoc, Cond, SwitchDiagnoser); diff --git a/clang/test/Parser/switch-typo-correction.cpp b/clang/test/Parser/switch-typo-correction.cpp new file mode 100644 --- /dev/null +++ b/clang/test/Parser/switch-typo-correction.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +namespace c { double xxx; } +namespace d { float xxx; } +namespace z { namespace xxx {} } + +void crash() { + switch (xxx) {} // expected-error{{use of undeclared identifier 'xxx'}} +}