[cfe-commits] r133984 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaType.cpp test/SemaCXX/condition.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Mon Jun 27 20:01:12 PDT 2011
Author: akirtzidis
Date: Mon Jun 27 22:01:12 2011
New Revision: 133984
URL: http://llvm.org/viewvc/llvm-project?rev=133984&view=rev
Log:
Remove the call to GetTypeForDeclarator in Sema::ActOnCXXConditionDeclaration.
No functionality change.
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaCXX/condition.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=133984&r1=133983&r2=133984&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Jun 27 22:01:12 2011
@@ -8913,25 +8913,13 @@
// 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;
}
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=133984&r1=133983&r2=133984&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Jun 27 22:01:12 2011
@@ -1728,6 +1728,7 @@
// have a type.
QualType T;
TypeSourceInfo *ReturnTypeInfo = 0;
+ TagDecl *OwnedTagDeclInternal = 0;
TypeProcessingState state(*this, D);
@@ -1752,7 +1753,7 @@
TagDecl* Owned = cast<TagDecl>(D.getDeclSpec().getRepAsDecl());
// Owned declaration is embedded in declarator.
Owned->setEmbeddedInDeclarator(true);
- if (OwnedDecl) *OwnedDecl = Owned;
+ OwnedTagDeclInternal = Owned;
}
break;
@@ -2456,6 +2457,39 @@
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);
}
Modified: cfe/trunk/test/SemaCXX/condition.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/condition.cpp?rev=133984&r1=133983&r2=133984&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/condition.cpp (original)
+++ cfe/trunk/test/SemaCXX/condition.cpp Mon Jun 27 22:01:12 2011
@@ -16,6 +16,7 @@
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}} \
More information about the cfe-commits
mailing list