From: Olivier Goffart Date: Fri, 9 Jan 2015 09:37:26 +0000 (+0000) Subject: Fix crash in typo correction while correcting enum within a struct in C X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=83d12ae2646c6b9db6df794c9510bb1747c3f780;p=clang Fix crash in typo correction while correcting enum within a struct in C git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225513 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 6351b7d115..422398ebeb 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -5991,8 +5991,10 @@ static ExprResult attemptRecovery(Sema &SemaRef, if (auto *NNS = TC.getCorrectionSpecifier()) Record = NNS->getAsType()->getAsCXXRecordDecl(); if (!Record) - Record = cast(ND->getDeclContext()->getRedeclContext()); - R.setNamingClass(Record); + Record = + dyn_cast(ND->getDeclContext()->getRedeclContext()); + if (Record) + R.setNamingClass(Record); // Detect and handle the case where the decl might be an implicit // member. diff --git a/test/Sema/typo-correction.c b/test/Sema/typo-correction.c index e4d14654cc..d8524b9d23 100644 --- a/test/Sema/typo-correction.c +++ b/test/Sema/typo-correction.c @@ -12,3 +12,14 @@ void PR21656() { a = b ? : 0; // expected-warning {{type specifier missing, defaults to 'int'}} \ // expected-error {{use of undeclared identifier 'b'}} + +struct ContainerStuct { + enum { SOME_ENUM }; // expected-note {{'SOME_ENUM' declared here}} +}; + +void func(int arg) { + switch (arg) { + case SOME_ENUM_: + ; // expected-error {{use of undeclared identifier 'SOME_ENUM_'; did you mean 'SOME_ENUM'}} + } +}