]> granicus.if.org Git - clang/commitdiff
Centralize all checks for a C++ tag definition inside a typename in
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 28 Jun 2011 03:01:18 +0000 (03:01 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 28 Jun 2011 03:01:18 +0000 (03:01 +0000)
Sema::GetTypeForDeclarator and remove its 'OwnedDecl' out parameter.

No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133986 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/Sema.h
lib/Sema/SemaDecl.cpp
lib/Sema/SemaExprCXX.cpp
lib/Sema/SemaType.cpp

index 724e1ea29cda6eac024c341ec21bb3739aa0488c..e2c8c4569cdc69f3721170ee32819bbd6f6433b3 100644 (file)
@@ -780,7 +780,6 @@ public:
   QualType BuildParenType(QualType T);
 
   TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S,
-                                       TagDecl **OwnedDecl = 0,
                                        bool AllowAutoInTypeName = false);
   TypeSourceInfo *GetTypeSourceInfoForDeclarator(Declarator &D, QualType T,
                                                TypeSourceInfo *ReturnTypeInfo);
index 25569be7b2893b738b8b7711defb93a160343760..efb06f66877c99e1a924f1cb193817a70d87866a 100644 (file)
@@ -2608,7 +2608,7 @@ Decl *Sema::BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS,
   }
 
   // Mock up a declarator.
-  Declarator Dc(DS, Declarator::TypeNameContext);
+  Declarator Dc(DS, Declarator::MemberContext);
   TypeSourceInfo *TInfo = GetTypeForDeclarator(Dc, S);
   assert(TInfo && "couldn't build declarator info for anonymous struct/union");
 
index c6443e988bc4a7cd9e75e7b3ab6c377fc7e1625d..f116f93234a24eebe104f59c5e87c68182a027d6 100644 (file)
@@ -828,7 +828,7 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
     }
   }
 
-  TypeSourceInfo *TInfo = GetTypeForDeclarator(D, /*Scope=*/0, /*OwnedDecl=*/0,
+  TypeSourceInfo *TInfo = GetTypeForDeclarator(D, /*Scope=*/0,
                                                /*AllowAuto=*/true);
   QualType AllocType = TInfo->getType();
   if (D.isInvalidType())
index a6905302790a0172e335dca9a8cf339c4086cd56..629a1a86ac83ec389d10415563867e9989ef5055 100644 (file)
@@ -1722,13 +1722,12 @@ static void DiagnoseIgnoredQualifiers(unsigned Quals,
 /// The result of this call will never be null, but the associated
 /// type may be a null type if there's an unrecoverable error.
 TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
-                                           TagDecl **OwnedDecl,
                                            bool AutoAllowedInTypeName) {
   // Determine the type of the declarator. Not all forms of declarator
   // have a type.
   QualType T;
   TypeSourceInfo *ReturnTypeInfo = 0;
-  TagDecl *OwnedTagDeclInternal = 0;
+  TagDecl *OwnedTagDecl = 0;
 
   TypeProcessingState state(*this, D);
 
@@ -1750,10 +1749,9 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
     T = ConvertDeclSpecToType(*this, state);
     
     if (!D.isInvalidType() && D.getDeclSpec().isTypeSpecOwned()) {
-      TagDecl* Owned = cast<TagDecl>(D.getDeclSpec().getRepAsDecl());
+      OwnedTagDecl = cast<TagDecl>(D.getDeclSpec().getRepAsDecl());
       // Owned declaration is embedded in declarator.
-      Owned->setEmbeddedInDeclarator(true);
-      OwnedTagDeclInternal = Owned;
+      OwnedTagDecl->setEmbeddedInDeclarator(true);
     }
     break;
 
@@ -2458,39 +2456,46 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
   else if (D.isInvalidType())
     return Context.getTrivialTypeSourceInfo(T);
 
-  if (OwnedTagDeclInternal && OwnedDecl)
-    *OwnedDecl = OwnedTagDeclInternal;
-
   if (getLangOptions().CPlusPlus &&
-      OwnedTagDeclInternal && OwnedTagDeclInternal->isDefinition()) {
+      OwnedTagDecl && OwnedTagDecl->isDefinition()) {
     // Check the contexts where C++ forbids the declaration of a new class
     // or enumeration in a type-specifier-seq.
     switch (D.getContext()) {
     case Declarator::FileContext:
-    case Declarator::ObjCPrototypeContext:
-    case Declarator::KNRTypeListContext:
-    case Declarator::TypeNameContext:
     case Declarator::MemberContext:
     case Declarator::BlockContext:
     case Declarator::ForContext:
-    case Declarator::TemplateParamContext:
-    case Declarator::CXXCatchContext:
     case Declarator::BlockLiteralContext:
-    case Declarator::TemplateTypeArgContext:
+      // C++0x [dcl.type]p3:
+      //   A type-specifier-seq shall not define a class or enumeration unless
+      //   it appears in the type-id of an alias-declaration (7.1.3) that is not
+      //   the declaration of a template-declaration.
     case Declarator::AliasDeclContext:
+      break;
     case Declarator::AliasTemplateContext:
+      Diag(OwnedTagDecl->getLocation(),diag::err_type_defined_in_alias_template)
+        << Context.getTypeDeclType(OwnedTagDecl);
+      break;
+    case Declarator::TypeNameContext:
+    case Declarator::TemplateParamContext:
+    case Declarator::CXXCatchContext:
+    case Declarator::TemplateTypeArgContext:
+      Diag(OwnedTagDecl->getLocation(),diag::err_type_defined_in_type_specifier)
+        << Context.getTypeDeclType(OwnedTagDecl);
       break;
     case Declarator::PrototypeContext:
+    case Declarator::ObjCPrototypeContext:
+    case Declarator::KNRTypeListContext:
       // C++ [dcl.fct]p6:
       //   Types shall not be defined in return or parameter types.
-      Diag(OwnedTagDeclInternal->getLocation(), diag::err_type_defined_in_param_type)
-        << Context.getTypeDeclType(OwnedTagDeclInternal);
+      Diag(OwnedTagDecl->getLocation(), diag::err_type_defined_in_param_type)
+        << Context.getTypeDeclType(OwnedTagDecl);
       break;
     case Declarator::ConditionContext:
       // C++ 6.4p2:
       // The type-specifier-seq shall not contain typedef and shall not declare
       // a new class or enumeration.
-      Diag(OwnedTagDeclInternal->getLocation(), diag::err_type_defined_in_condition);
+      Diag(OwnedTagDecl->getLocation(), diag::err_type_defined_in_condition);
       break;
     }
   }
@@ -2916,8 +2921,7 @@ TypeResult Sema::ActOnTypeName(Scope *S, Declarator &D) {
   // the parser.
   assert(D.getIdentifier() == 0 && "Type name should have no identifier!");
 
-  TagDecl *OwnedTag = 0;
-  TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S, &OwnedTag);
+  TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S);
   QualType T = TInfo->getType();
   if (D.isInvalidType())
     return true;
@@ -2925,19 +2929,6 @@ TypeResult Sema::ActOnTypeName(Scope *S, Declarator &D) {
   if (getLangOptions().CPlusPlus) {
     // Check that there are no default arguments (C++ only).
     CheckExtraCXXDefaultArguments(D);
-
-    // C++0x [dcl.type]p3:
-    //   A type-specifier-seq shall not define a class or enumeration unless
-    //   it appears in the type-id of an alias-declaration (7.1.3) that is not
-    //   the declaration of a template-declaration.
-    if (OwnedTag && OwnedTag->isDefinition()) {
-      if (D.getContext() == Declarator::AliasTemplateContext)
-        Diag(OwnedTag->getLocation(), diag::err_type_defined_in_alias_template)
-          << Context.getTypeDeclType(OwnedTag);
-      else if (D.getContext() != Declarator::AliasDeclContext)
-        Diag(OwnedTag->getLocation(), diag::err_type_defined_in_type_specifier)
-          << Context.getTypeDeclType(OwnedTag);
-    }
   }
 
   return CreateParsedType(T, TInfo);