From d6ab8744dc68e7dec176a5899e1d68a4a8de91f0 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Thu, 28 May 2009 23:31:59 +0000 Subject: When we parse a tag specifier, keep track of whether that tag specifier resulted in the creation of a new TagDecl node, which happens either when the tag specifier was a definition or when the tag specifier was the first declaration of that tag type. This information has several uses, the first of which is implemented in this commit: 1) In C++, one is not allowed to define tag types within a type specifier (e.g., static_cast(0) is ill-formed) or within the result or parameter types of a function. We now diagnose this. 2) We can extend DeclGroups to contain information about any tags that are declared/defined within the declaration specifiers of a variable, e.g., struct Point { int x, y, z; } p; This will help improve AST printing and template instantiation, among other things. 3) For C99, we can keep track of whether a tag type is defined within the type of a parameter, to properly cope with cases like, e.g., int bar(struct T2 { int x; } y) { struct T2 z; } We can also do similar things wherever there is a type specifier, e.g., to keep track of where the definition of S occurs in this legal C99 code: (struct S { int x, y; } *)0 llvm-svn: 72555 --- clang/lib/Parse/ParseDeclCXX.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'clang/lib/Parse/ParseDeclCXX.cpp') diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index a7d3b52bd23..cfbd9097f72 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -479,6 +479,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, // FIXME: When TK == TK_Reference and we have a template-id, we need // to turn that template-id into a type. + bool Owned = false; if (TemplateId && TK != Action::TK_Reference) { // Explicit specialization, class template partial specialization, // or explicit instantiation. @@ -582,7 +583,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, // Declaration or definition of a class type TagOrTempResult = Actions.ActOnTag(CurScope, TagType, TK, StartLoc, SS, - Name, NameLoc, Attr, AS); + Name, NameLoc, Attr, AS, Owned); } // Parse the optional base clause (C++ only). @@ -608,7 +609,7 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind, } if (DS.SetTypeSpecType(TagType, StartLoc, PrevSpec, - TagOrTempResult.get().getAs())) + TagOrTempResult.get().getAs(), Owned)) Diag(StartLoc, diag::err_invalid_decl_spec_combination) << PrevSpec; if (DS.isFriendSpecified()) -- cgit v1.2.3