diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2011-02-09 22:20:01 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2011-02-09 22:20:01 +0000 |
commit | 7f53253223b29d77f1e9c5c0ce93a19932761b77 (patch) | |
tree | 241f0561678ba7020b09d3088260ca62e378b2e5 /lib/Sema/SemaDeclObjC.cpp | |
parent | bf36e25224b959595af84337339103ebc542ff8c (diff) |
Fix scoping of method declarations and issue
warning when same parameter name used multiple times.
// rdar://8877730
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125229 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDeclObjC.cpp')
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index a2f6b516be..a3d93ab85e 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -1664,6 +1664,7 @@ bool containsInvalidMethodImplAttribute(const AttrVec &A) { } Decl *Sema::ActOnMethodDeclaration( + Scope *S, SourceLocation MethodLoc, SourceLocation EndLoc, tok::TokenKind MethodType, Decl *ClassDecl, ObjCDeclSpec &ReturnQT, ParsedType ReturnType, @@ -1721,6 +1722,20 @@ Decl *Sema::ActOnMethodDeclaration( ArgType = adjustParameterType(ArgType); } + LookupResult R(*this, ArgInfo[i].Name, ArgInfo[i].NameLoc, + LookupOrdinaryName, ForRedeclaration); + LookupName(R, S); + if (R.isSingleResult()) { + NamedDecl *PrevDecl = R.getFoundDecl(); + if (S->isDeclScope(PrevDecl)) { + // FIXME. This should be an error; but will break projects. + Diag(ArgInfo[i].NameLoc, diag::warn_method_param_redefinition) + << ArgInfo[i].Name; + Diag(PrevDecl->getLocation(), + diag::note_previous_declaration); + } + } + ParmVarDecl* Param = ParmVarDecl::Create(Context, ObjCMethod, ArgInfo[i].NameLoc, ArgInfo[i].Name, ArgType, DI, @@ -1739,9 +1754,12 @@ Decl *Sema::ActOnMethodDeclaration( // Apply the attributes to the parameter. ProcessDeclAttributeList(TUScope, Param, ArgInfo[i].ArgAttrs); + S->AddDecl(Param); + IdResolver.AddDecl(Param); + Params.push_back(Param); } - + for (unsigned i = 0, e = CNumArgs; i != e; ++i) { ParmVarDecl *Param = cast<ParmVarDecl>(CParamInfo[i].Param); QualType ArgType = Param->getType(); @@ -1757,8 +1775,7 @@ Decl *Sema::ActOnMethodDeclaration( Param->setInvalidDecl(); } Param->setDeclContext(ObjCMethod); - if (Param->getDeclName()) - IdResolver.RemoveDecl(Param); + Params.push_back(Param); } |