]> granicus.if.org Git - clang/commitdiff
Plug an abstraction leak and fix a crasher in DiagnoseInvalidRedeclaration
authorKaelyn Uhrain <rikka@google.com>
Wed, 14 Sep 2011 19:37:32 +0000 (19:37 +0000)
committerKaelyn Uhrain <rikka@google.com>
Wed, 14 Sep 2011 19:37:32 +0000 (19:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139718 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/TypoCorrection.h
lib/Sema/SemaDecl.cpp
test/SemaCXX/function-redecl.cpp

index 480a71af890b5b2536a8f79a9e5a675327f2d8c7..9537c3031dcbf929a2a9b98c0505c87056c5ff0d 100644 (file)
@@ -118,7 +118,9 @@ public:
   }
 
   typedef llvm::SmallVector<NamedDecl*, 1>::iterator decl_iterator;
-  decl_iterator begin() { return CorrectionDecls.begin(); }
+  decl_iterator begin() {
+    return isKeyword() ? CorrectionDecls.end() : CorrectionDecls.begin();
+  }
   decl_iterator end() { return CorrectionDecls.end(); }
 
 private:
index 96531d41459bc1e78f4ac234297be0925a970329..abc3cf1938f13c76348f206d982ce44d08916ac7 100644 (file)
@@ -4284,8 +4284,6 @@ static void DiagnoseInvalidRedeclaration(Sema &S, FunctionDecl *NewFD,
   } else if ((Correction = S.CorrectTypo(Prev.getLookupNameInfo(),
                                          Prev.getLookupKind(), 0, 0, DC)) &&
              Correction.getCorrection() != Name) {
-    DiagMsg = isFriendDecl ? diag::err_no_matching_local_friend_suggest
-                           : diag::err_member_def_does_not_match_suggest;
     for (TypoCorrection::decl_iterator CDecl = Correction.begin(),
                                     CDeclEnd = Correction.end();
          CDecl != CDeclEnd; ++CDecl) {
@@ -4299,8 +4297,15 @@ static void DiagnoseInvalidRedeclaration(Sema &S, FunctionDecl *NewFD,
         NearMatches.push_back(std::make_pair(FD, ParamNum));
       }
     }
+    if (!NearMatches.empty())
+      DiagMsg = isFriendDecl ? diag::err_no_matching_local_friend_suggest
+                             : diag::err_member_def_does_not_match_suggest;
   }
 
+  // Ignore the correction if it didn't yield any close FunctionDecl matches
+  if (Correction && NearMatches.empty())
+    Correction = TypoCorrection();
+
   if (Correction)
     S.Diag(NewFD->getLocation(), DiagMsg)
         << Name << DC << Correction.getQuoted(S.getLangOptions())
index b31e42e88adbae7c2f2e34c34fe1b9a660fd2c51..2bc04a6d077c99aef2bfe6c56af4b4f50718461d 100644 (file)
@@ -70,3 +70,12 @@ using test1::Foo;
 void Bar::f(Foo::Inner foo) { // expected-error {{out-of-line definition of 'f' does not match any declaration in 'Bar'}}
   (void)foo;
 }
+
+class Crash {
+ public:
+  void GetCart(int count) const;
+};
+// This out-of-line definition was fine...
+void Crash::cart(int count) const {} // expected-error {{out-of-line definition of 'cart' does not match any declaration in 'Crash'}}
+// ...while this one crashed clang
+void Crash::chart(int count) const {} // expected-error {{out-of-line definition of 'chart' does not match any declaration in 'Crash'}}