diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-04-12 21:49:30 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-04-12 21:49:30 +0000 |
| commit | ffaa0e6919b0b369cd1e8009f45127ffe681a5b8 (patch) | |
| tree | d2d327869de8a2f973bea43e532898c5e989b6a4 /clang/include | |
| parent | 14bdb7843057023b1847e37efbd7381a46bf6e5b (diff) | |
| download | bcm5719-llvm-ffaa0e6919b0b369cd1e8009f45127ffe681a5b8.tar.gz bcm5719-llvm-ffaa0e6919b0b369cd1e8009f45127ffe681a5b8.zip | |
Diagnose invalid uses of tagged types with a missing tag. For example, in:
struct xyz { int y; };
enum abc { ZZZ };
static xyz b;
abc c;
we used to produce:
t2.c:4:8: error: unknown type name 'xyz'
static xyz b;
^
t2.c:5:1: error: unknown type name 'abc'
abc c;
^
we now produce:
t2.c:4:8: error: use of tagged type 'xyz' without 'struct' tag
static xyz b;
^
struct
t2.c:5:1: error: use of tagged type 'abc' without 'enum' tag
abc c;
^
enum
GCC produces the normal:
t2.c:4: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘b’
t2.c:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘c’
rdar://6783347
llvm-svn: 68914
Diffstat (limited to 'clang/include')
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticParseKinds.td | 2 | ||||
| -rw-r--r-- | clang/include/clang/Parse/Action.h | 9 | ||||
| -rw-r--r-- | clang/include/clang/Parse/Parser.h | 6 |
3 files changed, 15 insertions, 2 deletions
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 66a48cffb02..5e97faa96da 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -145,6 +145,8 @@ def err_invalid_decl_spec_combination : Error< "cannot combine with previous '%0' declaration specifier">; def err_unknown_typename : Error< "unknown type name %0">; +def err_use_of_tag_name_without_tag : Error< + "use of tagged type %0 without '%1' tag">; /// Objective-C parser diagnostics diff --git a/clang/include/clang/Parse/Action.h b/clang/include/clang/Parse/Action.h index 699d5711466..df54da46f6c 100644 --- a/clang/include/clang/Parse/Action.h +++ b/clang/include/clang/Parse/Action.h @@ -139,6 +139,15 @@ public: virtual TypeTy *getTypeName(IdentifierInfo &II, SourceLocation NameLoc, Scope *S, const CXXScopeSpec *SS = 0) = 0; + /// isTagName() - This method is called *for error recovery purposes only* + /// to determine if the specified name is a valid tag name ("struct foo"). If + /// so, this returns the TST for the tag corresponding to it (TST_enum, + /// TST_union, TST_struct, TST_class). This is used to diagnose cases in C + /// where the user forgot to specify the tag. + virtual DeclSpec::TST isTagName(IdentifierInfo &II, Scope *S) { + return DeclSpec::TST_unspecified; + } + /// isCurrentClassName - Return true if the specified name is the /// name of the innermost C++ class type currently being defined. virtual bool isCurrentClassName(const IdentifierInfo &II, Scope *S, diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 3e09a2cc535..f5a00065df1 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -825,7 +825,8 @@ private: void ParseObjCTypeQualifierList(ObjCDeclSpec &DS); - void ParseEnumSpecifier(DeclSpec &DS, AccessSpecifier AS = AS_none); + void ParseEnumSpecifier(SourceLocation TagLoc, DeclSpec &DS, + AccessSpecifier AS = AS_none); void ParseEnumBody(SourceLocation StartLoc, DeclPtrTy TagDecl); void ParseStructUnionBody(SourceLocation StartLoc, unsigned TagType, DeclPtrTy TagDecl); @@ -1012,7 +1013,8 @@ private: // C++ 9: classes [class] and C structs/unions. TypeResult ParseClassName(SourceLocation &EndLocation, const CXXScopeSpec *SS = 0); - void ParseClassSpecifier(DeclSpec &DS, + void ParseClassSpecifier(tok::TokenKind TagTokKind, SourceLocation TagLoc, + DeclSpec &DS, TemplateParameterLists *TemplateParams = 0, AccessSpecifier AS = AS_none); void ParseCXXMemberSpecification(SourceLocation StartLoc, unsigned TagType, |

