]> granicus.if.org Git - clang/commitdiff
Fix crash in typo correction while correcting enum within a struct in C
authorOlivier Goffart <ogoffart@woboq.com>
Fri, 9 Jan 2015 09:37:26 +0000 (09:37 +0000)
committerOlivier Goffart <ogoffart@woboq.com>
Fri, 9 Jan 2015 09:37:26 +0000 (09:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225513 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprCXX.cpp
test/Sema/typo-correction.c

index 6351b7d115f036b4c95b8a3fec45642065ca878b..422398ebeb1ed2773309a71b53b8c7c45e517825 100644 (file)
@@ -5991,8 +5991,10 @@ static ExprResult attemptRecovery(Sema &SemaRef,
       if (auto *NNS = TC.getCorrectionSpecifier())
         Record = NNS->getAsType()->getAsCXXRecordDecl();
       if (!Record)
-        Record = cast<CXXRecordDecl>(ND->getDeclContext()->getRedeclContext());
-      R.setNamingClass(Record);
+        Record =
+            dyn_cast<CXXRecordDecl>(ND->getDeclContext()->getRedeclContext());
+      if (Record)
+        R.setNamingClass(Record);
 
       // Detect and handle the case where the decl might be an implicit
       // member.
index e4d14654cc9de3eb2428ace1596b9db639843959..d8524b9d234cf7ada18420169ff00b322c9e070f 100644 (file)
@@ -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'}}
+  }
+}