[cfe-commits] r139718 - in /cfe/trunk: include/clang/Sema/TypoCorrection.h lib/Sema/SemaDecl.cpp test/SemaCXX/function-redecl.cpp

Kaelyn Uhrain rikka at google.com
Wed Sep 14 12:37:32 PDT 2011


Author: rikka
Date: Wed Sep 14 14:37:32 2011
New Revision: 139718

URL: http://llvm.org/viewvc/llvm-project?rev=139718&view=rev
Log:
Plug an abstraction leak and fix a crasher in DiagnoseInvalidRedeclaration

Modified:
    cfe/trunk/include/clang/Sema/TypoCorrection.h
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/function-redecl.cpp

Modified: cfe/trunk/include/clang/Sema/TypoCorrection.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/TypoCorrection.h?rev=139718&r1=139717&r2=139718&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/TypoCorrection.h (original)
+++ cfe/trunk/include/clang/Sema/TypoCorrection.h Wed Sep 14 14:37:32 2011
@@ -118,7 +118,9 @@
   }
 
   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:

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=139718&r1=139717&r2=139718&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Sep 14 14:37:32 2011
@@ -4284,8 +4284,6 @@
   } 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 @@
         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())

Modified: cfe/trunk/test/SemaCXX/function-redecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/function-redecl.cpp?rev=139718&r1=139717&r2=139718&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/function-redecl.cpp (original)
+++ cfe/trunk/test/SemaCXX/function-redecl.cpp Wed Sep 14 14:37:32 2011
@@ -70,3 +70,12 @@
 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'}}





More information about the cfe-commits mailing list