Skip to content

[ObjC] Name lookup in methods shouldn't allow shadowing types #9632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions clang/lib/Parse/ParseObjc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,7 @@ Decl *Parser::ParseObjCMethodDecl(SourceLocation mLoc,

SmallVector<const IdentifierInfo *, 12> KeyIdents;
SmallVector<SourceLocation, 12> KeyLocs;
SmallVector<ParmVarDecl *, 12> ObjCParamInfo;
SmallVector<SemaObjC::ObjCArgInfo, 12> ArgInfos;
ParseScope PrototypeScope(this, Scope::FunctionPrototypeScope |
Scope::FunctionDeclarationScope | Scope::DeclScope);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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<ParmVarDecl *, 12> 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),
Expand Down
7 changes: 7 additions & 0 deletions clang/test/SemaObjC/method-param-named-id.m
Original file line number Diff line number Diff line change
@@ -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