// new class or enumeration.
assert(D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_typedef &&
"Parser allowed 'typedef' as storage class of condition decl.");
-
- TagDecl *OwnedTag = 0;
- TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S, &OwnedTag);
- QualType Ty = TInfo->getType();
-
- if (Ty->isFunctionType()) { // The declarator shall not specify a function...
- // We exit without creating a CXXConditionDeclExpr because a FunctionDecl
- // would be created and CXXConditionDeclExpr wants a VarDecl.
- Diag(D.getIdentifierLoc(), diag::err_invalid_use_of_function_type)
+
+ Decl *Dcl = ActOnDeclarator(S, D);
+ if (isa<FunctionDecl>(Dcl)) { // The declarator shall not specify a function.
+ Diag(Dcl->getLocation(), diag::err_invalid_use_of_function_type)
<< D.getSourceRange();
return DeclResult();
- } 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);
}
-
- Decl *Dcl = ActOnDeclarator(S, D);
- if (!Dcl)
- return DeclResult();
return Dcl;
}
// have a type.
QualType T;
TypeSourceInfo *ReturnTypeInfo = 0;
+ TagDecl *OwnedTagDeclInternal = 0;
TypeProcessingState state(*this, D);
TagDecl* Owned = cast<TagDecl>(D.getDeclSpec().getRepAsDecl());
// Owned declaration is embedded in declarator.
Owned->setEmbeddedInDeclarator(true);
- if (OwnedDecl) *OwnedDecl = Owned;
+ OwnedTagDeclInternal = Owned;
}
break;
return Context.getNullTypeSourceInfo();
else if (D.isInvalidType())
return Context.getTrivialTypeSourceInfo(T);
+
+ if (OwnedTagDeclInternal && OwnedDecl)
+ *OwnedDecl = OwnedTagDeclInternal;
+
+ if (getLangOptions().CPlusPlus &&
+ OwnedTagDeclInternal && OwnedTagDeclInternal->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::PrototypeContext:
+ 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:
+ case Declarator::AliasDeclContext:
+ case Declarator::AliasTemplateContext:
+ 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);
+ break;
+ }
+ }
+
return GetTypeSourceInfoForDeclarator(D, T, ReturnTypeInfo);
}
for (;s;) ; // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}}
switch (s) {} // expected-error {{statement requires expression of integer type ('struct S' invalid)}}
+ while (struct NewS *x=0) ;
while (struct S {} *x=0) ; // expected-error {{types may not be defined in conditions}}
while (struct {} *x=0) ; // expected-error {{types may not be defined in conditions}}
switch (enum {E} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{cannot initialize}} \