diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-11-19 17:10:50 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-11-19 17:10:50 +0000 |
| commit | 3a001f48e4492d7f4a8e0607a3ea3d206827bc33 (patch) | |
| tree | cce35805cc0f4f1cae651cf8e0d6e4cad2189d5b /clang | |
| parent | 2e49eaa92f7e33469dd5913c243e7cf5e27db70b (diff) | |
| download | bcm5719-llvm-3a001f48e4492d7f4a8e0607a3ea3d206827bc33.tar.gz bcm5719-llvm-3a001f48e4492d7f4a8e0607a3ea3d206827bc33.zip | |
When parsing something that looks like an ill-formed
protocol-qualifier list without a leading type (e.g., <#blah#>), don't
complain about it being an archaic protocol-qualifier list unless it
actually parses as one.
llvm-svn: 119805
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/include/clang/Parse/Parser.h | 2 | ||||
| -rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 9 | ||||
| -rw-r--r-- | clang/lib/Parse/ParseObjc.cpp | 7 | ||||
| -rw-r--r-- | clang/test/Parser/placeholder-recovery.m | 12 |
4 files changed, 21 insertions, 9 deletions
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index f8ca18afa81..e94225813e2 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -951,7 +951,7 @@ private: bool WarnOnDeclarations, SourceLocation &LAngleLoc, SourceLocation &EndProtoLoc); - void ParseObjCProtocolQualifiers(DeclSpec &DS); + bool ParseObjCProtocolQualifiers(DeclSpec &DS); void ParseObjCInterfaceDeclList(Decl *interfaceDecl, tok::ObjCKeywordKind contextKey); Decl *ParseObjCAtProtocolDeclaration(SourceLocation atLoc, diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index ed58a92323d..121289696db 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -1434,11 +1434,10 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, if (DS.hasTypeSpecifier() || !getLang().ObjC1) goto DoneWithDeclSpec; - ParseObjCProtocolQualifiers(DS); - - Diag(Loc, diag::warn_objc_protocol_qualifier_missing_id) - << FixItHint::CreateInsertion(Loc, "id") - << SourceRange(Loc, DS.getSourceRange().getEnd()); + if (!ParseObjCProtocolQualifiers(DS)) + Diag(Loc, diag::warn_objc_protocol_qualifier_missing_id) + << FixItHint::CreateInsertion(Loc, "id") + << SourceRange(Loc, DS.getSourceRange().getEnd()); // Need to support trailing type qualifiers (e.g. "id<p> const"). // If a type specifier follows, it will be diagnosed elsewhere. diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp index c01bea9cb5a..456c9c72820 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/lib/Parse/ParseObjc.cpp @@ -1038,18 +1038,19 @@ ParseObjCProtocolReferences(llvm::SmallVectorImpl<Decl *> &Protocols, /// \brief Parse the Objective-C protocol qualifiers that follow a typename /// in a decl-specifier-seq, starting at the '<'. -void Parser::ParseObjCProtocolQualifiers(DeclSpec &DS) { +bool Parser::ParseObjCProtocolQualifiers(DeclSpec &DS) { assert(Tok.is(tok::less) && "Protocol qualifiers start with '<'"); assert(getLang().ObjC1 && "Protocol qualifiers only exist in Objective-C"); SourceLocation LAngleLoc, EndProtoLoc; llvm::SmallVector<Decl *, 8> ProtocolDecl; llvm::SmallVector<SourceLocation, 8> ProtocolLocs; - ParseObjCProtocolReferences(ProtocolDecl, ProtocolLocs, false, - LAngleLoc, EndProtoLoc); + bool Result = ParseObjCProtocolReferences(ProtocolDecl, ProtocolLocs, false, + LAngleLoc, EndProtoLoc); DS.setProtocolQualifiers(ProtocolDecl.data(), ProtocolDecl.size(), ProtocolLocs.data(), LAngleLoc); if (EndProtoLoc.isValid()) DS.SetRangeEnd(EndProtoLoc); + return Result; } diff --git a/clang/test/Parser/placeholder-recovery.m b/clang/test/Parser/placeholder-recovery.m new file mode 100644 index 00000000000..1fc154955d5 --- /dev/null +++ b/clang/test/Parser/placeholder-recovery.m @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// FIXME: We could do much better with this, if we recognized +// placeholders somehow. However, we're content with not generating +// bogus 'archaic' warnings with bad location info. +@protocol <#protocol name#> <NSObject> // expected-error 2{{expected identifier}} \ +// expected-error{{cannot find protocol declaration for 'NSObject'}} \ +// expected-warning{{protocol qualifiers without 'id'}} + +<#methods#> // expected-error{{expected identifier}} + +@end // expected-error{{prefix attribute}} |

