diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp index 45929e6a48d8a..86210ab7bac2b 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/lib/Parse/ParseObjc.cpp @@ -1455,7 +1455,7 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, SmallVector KeyIdents; SmallVector KeyLocs; - SmallVector ObjCParamInfo; + SmallVector ArgInfos; ParseScope PrototypeScope(this, Scope::FunctionPrototypeScope | Scope::FunctionDeclarationScope | Scope::DeclScope); @@ -1496,9 +1496,7 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, ArgInfo.NameLoc = Tok.getLocation(); ConsumeToken(); // Eat the identifier. - ParmVarDecl *Param = Actions.ObjC().ActOnMethodParmDeclaration( - getCurScope(), ArgInfo, ObjCParamInfo.size(), MethodDefinition); - ObjCParamInfo.push_back(Param); + ArgInfos.push_back(ArgInfo); KeyIdents.push_back(SelIdent); KeyLocs.push_back(selLoc); @@ -1558,6 +1556,17 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc, nullptr)); } + // Turn ArgInfos into parameters. This must happen after parsing all + // parameters for bug compatibility with previous versions of Clang. (For + // instance, if a method declares a parameter called "id", that parameter must + // not shadow the "id" type.) + SmallVector ObjCParamInfo; + for (auto &ArgInfo : ArgInfos) { + ParmVarDecl *Param = Actions.ObjC().ActOnMethodParmDeclaration( + getCurScope(), ArgInfo, ObjCParamInfo.size(), MethodDefinition); + ObjCParamInfo.push_back(Param); + } + // FIXME: Add support for optional parameter list... // If attributes exist after the method, parse them. MaybeParseAttributes(PAKM_CXX11 | (getLangOpts().ObjC ? PAKM_GNU : 0), diff --git a/clang/test/SemaObjC/method-param-named-id.m b/clang/test/SemaObjC/method-param-named-id.m new file mode 100644 index 0000000000000..8269c31116c32 --- /dev/null +++ b/clang/test/SemaObjC/method-param-named-id.m @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s + + +@interface Foo +-(void)paramNamedID:(int)id usesIDType:(id)notShadowed; +-(void)paramNamedID:(int)id, id notShadowed; // expected-warning{{use of C-style parameters in Objective-C method declarations is deprecated}} +@end