[cfe-commits] r96769 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/Sema/arg-duplicate.c test/Sema/block-args.c test/SemaCXX/default2.cpp
Chris Lattner
sabre at nondot.org
Sun Feb 21 16:40:25 PST 2010
Author: lattner
Date: Sun Feb 21 18:40:25 2010
New Revision: 96769
URL: http://llvm.org/viewvc/llvm-project?rev=96769&view=rev
Log:
Add 'previous declaration is here' note for param redefinition
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);
^
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/arg-duplicate.c
cfe/trunk/test/Sema/block-args.c
cfe/trunk/test/SemaCXX/default2.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=96769&r1=96768&r2=96769&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Feb 21 18:40:25 2010
@@ -492,8 +492,7 @@
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">;
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=96769&r1=96768&r2=96769&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Feb 21 18:40:25 2010
@@ -3878,9 +3878,7 @@
<< 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 @@
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;
Modified: cfe/trunk/test/Sema/arg-duplicate.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/arg-duplicate.c?rev=96769&r1=96768&r2=96769&view=diff
==============================================================================
--- cfe/trunk/test/Sema/arg-duplicate.c (original)
+++ cfe/trunk/test/Sema/arg-duplicate.c Sun Feb 21 18:40:25 2010
@@ -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;
Modified: cfe/trunk/test/Sema/block-args.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-args.c?rev=96769&r1=96768&r2=96769&view=diff
==============================================================================
--- cfe/trunk/test/Sema/block-args.c (original)
+++ cfe/trunk/test/Sema/block-args.c Sun Feb 21 18:40:25 2010
@@ -6,7 +6,8 @@
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; });
Modified: cfe/trunk/test/SemaCXX/default2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/default2.cpp?rev=96769&r1=96768&r2=96769&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/default2.cpp (original)
+++ cfe/trunk/test/SemaCXX/default2.cpp Sun Feb 21 18:40:25 2010
@@ -16,7 +16,8 @@
}
-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;
}
More information about the cfe-commits
mailing list