]> granicus.if.org Git - clang/commitdiff
Check whether a tag was defined in a C++ condition declaration using GetTypeForDeclar...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 11 Aug 2009 05:20:41 +0000 (05:20 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 11 Aug 2009 05:20:41 +0000 (05:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@78644 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprCXX.cpp

index fde61e885629fd3633f4eb1a344a98fc3131d275..20f69069a5a4ec75223dac24b58939b8d001d303 100644 (file)
@@ -747,7 +747,8 @@ Sema::ActOnCXXConditionDeclarationExpr(Scope *S, SourceLocation StartLoc,
   assert(D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_typedef &&
          "Parser allowed 'typedef' as storage class of condition decl.");
 
-  QualType Ty = GetTypeForDeclarator(D, S);
+  TagDecl *OwnedTag = 0;
+  QualType Ty = GetTypeForDeclarator(D, S, /*Skip=*/0, &OwnedTag);
   
   if (Ty->isFunctionType()) { // The declarator shall not specify a function...
     // We exit without creating a CXXConditionDeclExpr because a FunctionDecl
@@ -757,18 +758,9 @@ Sema::ActOnCXXConditionDeclarationExpr(Scope *S, SourceLocation StartLoc,
   } else if (Ty->isArrayType()) { // ...or an array.
     Diag(StartLoc, diag::err_invalid_use_of_array_type)
       << SourceRange(StartLoc, EqualLoc);
-  } else if (const RecordType *RT = Ty->getAs<RecordType>()) {
-    RecordDecl *RD = RT->getDecl();
-    // The type-specifier-seq shall not declare a new class...
-    if (RD->isDefinition() &&
-        (RD->getIdentifier() == 0 || S->isDeclScope(DeclPtrTy::make(RD))))
-      Diag(RD->getLocation(), diag::err_type_defined_in_condition);
-  } else if (const EnumType *ET = Ty->getAsEnumType()) {
-    EnumDecl *ED = ET->getDecl();
-    // ...or enumeration.
-    if (ED->isDefinition() &&
-        (ED->getIdentifier() == 0 || S->isDeclScope(DeclPtrTy::make(ED))))
-      Diag(ED->getLocation(), diag::err_type_defined_in_condition);
+  } else if (OwnedTag && OwnedTag->isDefinition()) {
+    // The type-specifier-seq shall not declare a new class or enumeration.
+    Diag(OwnedTag->getLocation(), diag::err_type_defined_in_condition);
   }
 
   DeclPtrTy Dcl = ActOnDeclarator(S, D);