[cfe-commits] r133986 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Sema/SemaDecl.cpp lib/Sema/SemaExprCXX.cpp lib/Sema/SemaType.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Mon Jun 27 20:01:19 PDT 2011
Author: akirtzidis
Date: Mon Jun 27 22:01:18 2011
New Revision: 133986
URL: http://llvm.org/viewvc/llvm-project?rev=133986&view=rev
Log:
Centralize all checks for a C++ tag definition inside a typename in
Sema::GetTypeForDeclarator and remove its 'OwnedDecl' out parameter.
No functionality change.
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaType.cpp
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=133986&r1=133985&r2=133986&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Jun 27 22:01:18 2011
@@ -780,7 +780,6 @@
QualType BuildParenType(QualType T);
TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S,
- TagDecl **OwnedDecl = 0,
bool AllowAutoInTypeName = false);
TypeSourceInfo *GetTypeSourceInfoForDeclarator(Declarator &D, QualType T,
TypeSourceInfo *ReturnTypeInfo);
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=133986&r1=133985&r2=133986&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jun 27 22:01:18 2011
@@ -2608,7 +2608,7 @@
}
// 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");
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=133986&r1=133985&r2=133986&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon Jun 27 22:01:18 2011
@@ -828,7 +828,7 @@
}
}
- TypeSourceInfo *TInfo = GetTypeForDeclarator(D, /*Scope=*/0, /*OwnedDecl=*/0,
+ TypeSourceInfo *TInfo = GetTypeForDeclarator(D, /*Scope=*/0,
/*AllowAuto=*/true);
QualType AllocType = TInfo->getType();
if (D.isInvalidType())
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=133986&r1=133985&r2=133986&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Jun 27 22:01:18 2011
@@ -1722,13 +1722,12 @@
/// 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 @@
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 @@
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 @@
// 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 @@
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);
More information about the cfe-commits
mailing list