]> granicus.if.org Git - clang/commitdiff
Whenever we emit a typo-correction diagnostic, also emit a note
authorDouglas Gregor <dgregor@apple.com>
Thu, 7 Jan 2010 00:17:44 +0000 (00:17 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 7 Jan 2010 00:17:44 +0000 (00:17 +0000)
pointing to the declaration that we found that has that name (if it is
unique).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92877 91177308-0d34-0410-b5e6-96231b3b80d8

12 files changed:
lib/Sema/SemaCXXScopeSpec.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclCXX.cpp
lib/Sema/SemaDeclObjC.cpp
lib/Sema/SemaExpr.cpp
lib/Sema/SemaInit.cpp
lib/Sema/SemaTemplate.cpp
test/FixIt/typo.c
test/FixIt/typo.cpp
test/FixIt/typo.m
test/Sema/var-redecl.c
test/SemaObjC/undef-class-messagin-error.m

index 82d58eab1aad8d4d9b8ad6af1415ecd302a922f5..a8f118ebdd67271c409b12292f3db179dbcd0047 100644 (file)
@@ -446,6 +446,10 @@ Sema::CXXScopeTy *Sema::BuildCXXNestedNameSpecifier(Scope *S,
           << Name << Found.getLookupName()
           << CodeModificationHint::CreateReplacement(Found.getNameLoc(),
                                            Found.getLookupName().getAsString());
+      
+      if (NamedDecl *ND = Found.getAsSingle<NamedDecl>())
+        Diag(ND->getLocation(), diag::note_previous_decl)
+          << ND->getDeclName();
     } else
       Found.clear();
   }
index 9ed37f604fce02e888f593df3a14aab42fc78548..69e9ff9e9c6fd386c337c35b715026e799aa2472 100644 (file)
@@ -281,6 +281,9 @@ bool Sema::DiagnoseUnknownTypeName(const IdentifierInfo &II,
       else
         llvm_unreachable("could not have corrected a typo here");
 
+      Diag(Result->getLocation(), diag::note_previous_decl)
+        << Result->getDeclName();
+      
       SuggestedType = getTypeName(*Result->getIdentifier(), IILoc, S, SS);
       return true;
     }
@@ -580,6 +583,9 @@ ObjCInterfaceDecl *Sema::getObjCInterfaceDecl(IdentifierInfo *&Id,
         << Id << IDecl->getDeclName() 
         << CodeModificationHint::CreateReplacement(RecoverLoc, 
                                                    IDecl->getNameAsString());
+      Diag(IDecl->getLocation(), diag::note_previous_decl)
+        << IDecl->getDeclName();
+      
       Id = IDecl->getIdentifier();
     }
   }
index 2e6f8bc68766bfa73ad92e581c0ce1998236a35d..7ae0440b409d9ccc8d12eeecfd312a18b54d624a 100644 (file)
@@ -1072,6 +1072,8 @@ Sema::ActOnMemInitializer(DeclPtrTy ConstructorD,
               << MemberOrBase << true << R.getLookupName()
               << CodeModificationHint::CreateReplacement(R.getNameLoc(),
                                                R.getLookupName().getAsString());
+            Diag(Member->getLocation(), diag::note_previous_decl)
+              << Member->getDeclName();
 
             return BuildMemberInitializer(Member, (Expr**)Args, NumArgs, IdLoc,
                                           LParenLoc, RParenLoc);
index e5526746d9d0c93ffb0cf4add8196cc5119c8e2f..179255aedf925247ef5103ccd2b4f8a1207a66b7 100644 (file)
@@ -142,6 +142,8 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
           (PrevDecl = R.getAsSingle<ObjCInterfaceDecl>())) {
         Diag(SuperLoc, diag::err_undef_superclass_suggest)
           << SuperName << ClassName << PrevDecl->getDeclName();
+        Diag(PrevDecl->getLocation(), diag::note_previous_decl)
+          << PrevDecl->getDeclName();
       }
     }
 
@@ -335,6 +337,8 @@ Sema::FindProtocolDeclaration(bool WarnOnDeclarations,
           (PDecl = R.getAsSingle<ObjCProtocolDecl>())) {
         Diag(ProtocolId[i].second, diag::err_undeclared_protocol_suggest)
           << ProtocolId[i].first << R.getLookupName();
+        Diag(PDecl->getLocation(), diag::note_previous_decl)
+          << PDecl->getDeclName();
       }
     }
 
index 3d2ee742789fa1ac88fb94bfc72a9ed787d54bd3..730375e5cd34d0d78665162f8d19479436ee7af6 100644 (file)
@@ -943,7 +943,10 @@ bool Sema::DiagnoseEmptyLookup(Scope *S, const CXXScopeSpec &SS,
           << SS.getRange()
           << CodeModificationHint::CreateReplacement(R.getNameLoc(),
                                               R.getLookupName().getAsString());
-
+      if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
+        Diag(ND->getLocation(), diag::note_previous_decl)
+          << ND->getDeclName();
+      
       // Tell the callee to try to recover.
       return false;
     }
@@ -2400,6 +2403,9 @@ LookupMemberExprInRecord(Sema &SemaRef, LookupResult &R,
       << Name << DC << R.getLookupName() << SS.getRange()
       << CodeModificationHint::CreateReplacement(R.getNameLoc(),
                                          R.getLookupName().getAsString());
+    if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
+      SemaRef.Diag(ND->getLocation(), diag::note_previous_decl)
+        << ND->getDeclName();
     return false;
   } else {
     R.clear();
@@ -2881,6 +2887,8 @@ Sema::LookupMemberExpr(LookupResult &R, Expr *&BaseExpr,
             << IDecl->getDeclName() << MemberName << IV->getDeclName()
             << CodeModificationHint::CreateReplacement(R.getNameLoc(),
                                                        IV->getNameAsString());
+          Diag(IV->getLocation(), diag::note_previous_decl)
+            << IV->getDeclName();          
         }
       }
 
@@ -3060,6 +3068,10 @@ Sema::LookupMemberExpr(LookupResult &R, Expr *&BaseExpr,
         << MemberName << BaseType << Res.getLookupName()
         << CodeModificationHint::CreateReplacement(R.getNameLoc(),
                                            Res.getLookupName().getAsString());
+      ObjCPropertyDecl *Property = Res.getAsSingle<ObjCPropertyDecl>();
+      Diag(Property->getLocation(), diag::note_previous_decl)
+        << Property->getDeclName();          
+
       return LookupMemberExpr(Res, BaseExpr, IsArrow, OpLoc, SS,
                               FirstQualifierInScope, ObjCImpDecl);
     }
index 54d94f86ceca31c15954e987c7ff5b66c66eae13..c2a62cbc523769495008bd42a4ae73898dcf2de2 100644 (file)
@@ -1302,6 +1302,9 @@ InitListChecker::CheckDesignatedInitializer(InitListExpr *IList,
             << FieldName << CurrentObjectType << R.getLookupName()
             << CodeModificationHint::CreateReplacement(D->getFieldLoc(),
                                                R.getLookupName().getAsString());
+          SemaRef.Diag(ReplacementField->getLocation(), 
+                       diag::note_previous_decl)
+            << ReplacementField->getDeclName();
         } else {
           SemaRef.Diag(D->getFieldLoc(), diag::err_field_designator_unknown)
             << FieldName << CurrentObjectType;
index 8c6aa6a7d4a9426a60320e91cfc4b3a25aecfe4f..ecb89edcf7dfe2b82abc033427ed76da3f3badbb 100644 (file)
@@ -219,6 +219,9 @@ void Sema::LookupTemplateName(LookupResult &Found,
             << Name << Found.getLookupName()
             << CodeModificationHint::CreateReplacement(Found.getNameLoc(),
                                           Found.getLookupName().getAsString());
+        if (TemplateDecl *Template = Found.getAsSingle<TemplateDecl>())
+          Diag(Template->getLocation(), diag::note_previous_decl)
+            << Template->getDeclName();
       } else
         Found.clear();
     } else {
index d36e769ed0a2cf733f61b51b4db77829d58d7773..72e3d658e7b6aef6ee3f58256e18897e81c4d83c 100644 (file)
@@ -5,13 +5,14 @@ struct Point {
 };
 
 struct Rectangle {
-  struct Point top_left, bottom_right;
+  struct Point top_left, // expected-note{{'top_left' declared here}}
+               bottom_right;
 };
 
 enum Color { Red, Green, Blue };
 
 struct Window {
-  struct Rectangle bounds;
+  struct Rectangle bounds; // expected-note{{'bounds' declared here}}
   enum Color color;
 };
 
index 041b86a7f2c7b6d7dfa78764fd72d414fc5e81ab..ffeb18dde103e952b4bf0ef858448e7f01a62390 100644 (file)
@@ -1,15 +1,15 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 // RUN: %clang_cc1 -fsyntax-only -fixit -o - %s | %clang_cc1 -fsyntax-only -pedantic -Werror -x c++ -
 namespace std {
-  template<typename T> class basic_string { 
-    int find(const char *substr);
-    static const int npos = -1;
+  template<typename T> class basic_string { // expected-note 2{{'basic_string' declared here}}
+    int find(const char *substr); // expected-note{{'find' declared here}}
+    static const int npos = -1; // expected-note{{'npos' declared here}}
   };
 
-  typedef basic_string<char> string;
+  typedef basic_string<char> string; // expected-note 2{{'string' declared here}}
 }
 
-namespace otherstd {
+namespace otherstd { // expected-note 2{{'otherstd' declared here}}
   using namespace std;
 }
 
@@ -36,7 +36,7 @@ bool test_string(std::string s) {
 
 struct Base { };
 struct Derived : public Base {
-  int member;
+  int member; // expected-note 3{{'member' declared here}}
 
   Derived() : base(), // expected-error{{initializer 'base' does not name a non-static data member or base class; did you mean the base class 'Base'?}}
               ember() { } // expected-error{{initializer 'ember' does not name a non-static data member or base class; did you mean the member 'member'?}}
index cff5dd84eadabe9bb299653fe15aa9fd59bbd888..4c3ee5f60bc8de5fad0294ffcf513404c58eddfd 100644 (file)
@@ -12,24 +12,24 @@ void test() {
 }
 
 @protocol P1
-@property int *sprop;
+@property int *sprop; // expected-note{{'sprop' declared here}}
 @end
 
 @interface A
 {
-  int his_ivar;
+  int his_ivar; // expected-note 2{{'his_ivar' declared here}}
   float wibble;
 }
 
-@property int his_prop;
+@property int his_prop; // expected-note{{'his_prop' declared here}}
 @end
 
 @interface B : A <P1>
 {
-  int her_ivar;
+  int her_ivar; // expected-note 2{{'her_ivar' declared here}}
 }
 
-@property int her_prop;
+@property int her_prop; // expected-note{{'her_prop' declared here}}
 - (void)inst_method1:(int)a;
 + (void)class_method1;
 @end
@@ -60,13 +60,13 @@ void test_message_send(B* b) {
   [NSstring method:17]; // expected-error{{use of undeclared identifier 'NSstring'; did you mean 'NSString'?}}
 }
 
-@interface Collide
+@interface Collide // expected-note{{'Collide' declared here}}
 {
 @public
-  int value;
+  int value; // expected-note{{'value' declared here}}
 }
 
-@property int value;
+@property int value; // expected-note{{'value' declared here}}
 @end
 
 @implementation Collide
@@ -81,7 +81,7 @@ void test2(Collide *a) {
 @interface Derived : Collid // expected-error{{cannot find interface declaration for 'Collid', superclass of 'Derived'; did you mean 'Collide'?}}
 @end
 
-@protocol NetworkSocket
+@protocol NetworkSocket // expected-note{{'NetworkSocket' declared here}}
 - (int)send:(void*)buffer bytes:(int)bytes;
 @end
 
index e67499bcc4c98104d8c55c304eaec8a094359957..71d7ea1baee0fdcdcc36b1e86693c07e4ed918a3 100644 (file)
@@ -50,7 +50,7 @@ void outer_shadowing_test() {
   }
 }
 
-void g18(void) {
+void g18(void) { // expected-note{{'g18' declared here}}
   extern int g19;
 }
 int *p=&g19; // expected-error{{use of undeclared identifier 'g19'}} \
index 2a6d240840f780ee2ab355327aea8338eb3c546c..63e0b9dec32947547a00b4564b6a1f7684507db7 100644 (file)
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
-@interface _Child
+@interface _Child // expected-note{{'_Child' declared here}}
 + (int) flashCache;
 @end