]> granicus.if.org Git - clang/commitdiff
Add 'previous declaration is here' note for param redefinition
authorChris Lattner <sabre@nondot.org>
Mon, 22 Feb 2010 00:40:25 +0000 (00:40 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 22 Feb 2010 00:40:25 +0000 (00:40 +0000)
errors, e.g.:

t.c:1:21: error: redefinition of parameter 'x'
int test(int x, int x);
                    ^
t.c:1:14: note: previous declaration is here
int test(int x, int x);
             ^

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/Sema/arg-duplicate.c
test/Sema/block-args.c
test/SemaCXX/default2.cpp

index 682f20348dfef5b99526bbf26bad88494cc0dc7a..7c75f2fc7bf3b1c4a990bb20390167b9af799526 100644 (file)
@@ -492,8 +492,7 @@ def err_implicit_object_parameter_init : Error<
 
 def note_field_decl : Note<"member is declared here">;
 def note_bitfield_decl : Note<"bit-field is declared here">;
-def note_previous_decl : Note<
-  "%0 declared here">;
+def note_previous_decl : Note<"%0 declared here">;
 def note_member_synthesized_at : Note<
   "implicit default %select{constructor|copy constructor|"
   "copy assignment operator|destructor}0 for %1 first required here">;
index 2a9885c6a3cefe089ed0b5cc3ced2a2446d2b180..c59e8bad6678cebfe9178344a403c0534c1c963b 100644 (file)
@@ -3878,9 +3878,7 @@ Sema::ActOnParamDeclarator(Scope *S, Declarator &D) {
       << Context.getTypeDeclType(OwnedDecl);
   }
 
-  // TODO: CHECK FOR CONFLICTS, multiple decls with same name in one scope.
-  // Can this happen for params?  We already checked that they don't conflict
-  // among each other.  Here they can only shadow globals, which is ok.
+  // Check for redeclaration of parameters, e.g. int foo(int x, int x);
   IdentifierInfo *II = D.getIdentifier();
   if (II) {
     if (NamedDecl *PrevDecl = LookupSingleName(S, II, LookupOrdinaryName)) {
@@ -3891,6 +3889,7 @@ Sema::ActOnParamDeclarator(Scope *S, Declarator &D) {
         PrevDecl = 0;
       } else if (S->isDeclScope(DeclPtrTy::make(PrevDecl))) {
         Diag(D.getIdentifierLoc(), diag::err_param_redefinition) << II;
+        Diag(PrevDecl->getLocation(), diag::note_previous_declaration);
 
         // Recover by removing the name
         II = 0;
index ca091eb309e4e2a60a38dbd8e5f3bdaf19451d6e..feeb458a3f42b6fb7057d978f0fa76e7dece1432 100644 (file)
@@ -2,7 +2,8 @@
 
 int f3(y, x, 
        x)          // expected-error {{redefinition of parameter}}
-  int y, x, 
+  int y, 
+      x,           // expected-note {{previous declaration is here}}
       x;           // expected-error {{redefinition of parameter}}
 {
   return x + y; 
index a07c82e75afa902253edf3e7b769009cfc183580..970c60d51ddb8a43af57d97ade712ea834f4a2b7 100644 (file)
@@ -6,7 +6,8 @@ void test() {
   take(^(int x){});
   take(^(int x, int y){});
   take(^(int x, int y){});
-  take(^(int x, int x){});  // expected-error {{redefinition of parameter 'x'}}
+  take(^(int x,      // expected-note {{previous declaration is here}}
+         int x){});  // expected-error {{redefinition of parameter 'x'}}
 
 
   take(^(int x) { return x+1; });
index d2c44bd998a0ecb17d050cda93aa10ce905f7b24..e674260680fca2d7baafbb35df745fde143c77f7 100644 (file)
@@ -16,7 +16,8 @@ void i()
 }
 
 
-int f1(int i, int i, int j) { // expected-error {{redefinition of parameter 'i'}}
+int f1(int i,          // expected-note {{previous declaration is here}}
+       int i, int j) { // expected-error {{redefinition of parameter 'i'}}
   i = 17;
   return j;
 }