diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-12-13 22:49:22 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-12-13 22:49:22 +0000 |
commit | d0937224f383c7cc72c947119380f9713a070c73 (patch) | |
tree | 4a7ffd1e9f8fa276b23f555166bf429f1be2274b /lib/AST/Type.cpp | |
parent | 140a2bd77539b4537010d8cd6a0a3805ce724b3e (diff) |
Variadic templates: extend Type, NestedNameSpecifier, TemplateName,
and TemplateArgument with an operation that determines whether there
are any unexpanded parameter packs within that construct. Use this
information to diagnose the appearance of the names of parameter packs
that have not been expanded (C++ [temp.variadic]p5). Since this
property is checked often (every declaration, ever expression
statement, etc.), we extend Type and Expr with a bit storing the
result of this computation, rather than walking the AST each time to
determine whether any unexpanded parameter packs occur.
This commit is deficient in several ways, which will be remedied with
future commits:
- Expr has a bit to store the presence of an unexpanded parameter
pack, but it is never set.
- The error messages don't point out where the unexpanded parameter
packs were named in the type/expression, but they should.
- We don't check for unexpanded parameter packs in all of the places
where we should.
- Testing is sparse, pending the resolution of the above three
issues.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121724 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Type.cpp')
-rw-r--r-- | lib/AST/Type.cpp | 86 |
1 files changed, 76 insertions, 10 deletions
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index ed05a39305..127613ed32 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -63,6 +63,18 @@ unsigned ConstantArrayType::getMaxSizeBits(ASTContext &Context) { return Bits; } +DependentSizedArrayType::DependentSizedArrayType(ASTContext &Context, + QualType et, QualType can, + Expr *e, ArraySizeModifier sm, + unsigned tq, + SourceRange brackets) + : ArrayType(DependentSizedArray, et, can, sm, tq, + (et->containsUnexpandedParameterPack() || + (e && e->containsUnexpandedParameterPack()))), + Context(Context), SizeExpr((Stmt*) e), Brackets(brackets) +{ +} + void DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, QualType ET, @@ -75,6 +87,20 @@ void DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID, E->Profile(ID, Context, true); } +DependentSizedExtVectorType::DependentSizedExtVectorType(ASTContext &Context, + QualType ElementType, + QualType can, + Expr *SizeExpr, + SourceLocation loc) + : Type(DependentSizedExtVector, can, /*Dependent=*/true, + ElementType->isVariablyModifiedType(), + (ElementType->containsUnexpandedParameterPack() || + (SizeExpr && SizeExpr->containsUnexpandedParameterPack()))), + Context(Context), SizeExpr(SizeExpr), ElementType(ElementType), + loc(loc) +{ +} + void DependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, @@ -83,6 +109,28 @@ DependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID, SizeExpr->Profile(ID, Context, true); } +VectorType::VectorType(QualType vecType, unsigned nElements, QualType canonType, + VectorKind vecKind) + : Type(Vector, canonType, vecType->isDependentType(), + vecType->isVariablyModifiedType(), + vecType->containsUnexpandedParameterPack()), + ElementType(vecType) +{ + VectorTypeBits.VecKind = vecKind; + VectorTypeBits.NumElements = nElements; +} + +VectorType::VectorType(TypeClass tc, QualType vecType, unsigned nElements, + QualType canonType, VectorKind vecKind) + : Type(tc, canonType, vecType->isDependentType(), + vecType->isVariablyModifiedType(), + vecType->containsUnexpandedParameterPack()), + ElementType(vecType) +{ + VectorTypeBits.VecKind = vecKind; + VectorTypeBits.NumElements = nElements; +} + /// getArrayElementTypeNoTypeQual - If this is an array type, return the /// element type of the array, potentially with type qualifiers missing. /// This method should never be used when type qualifiers are meaningful. @@ -321,8 +369,9 @@ const RecordType *Type::getAsUnionType() const { ObjCObjectType::ObjCObjectType(QualType Canonical, QualType Base, ObjCProtocolDecl * const *Protocols, unsigned NumProtocols) - : Type(ObjCObject, Canonical, false, false), - BaseType(Base) { + : Type(ObjCObject, Canonical, false, false, false), + BaseType(Base) +{ ObjCObjectTypeBits.NumProtocols = NumProtocols; assert(getNumProtocols() == NumProtocols && "bitfield overflow in protocol count"); @@ -924,12 +973,17 @@ DependentTemplateSpecializationType::DependentTemplateSpecializationType( unsigned NumArgs, const TemplateArgument *Args, QualType Canon) : TypeWithKeyword(Keyword, DependentTemplateSpecialization, Canon, true, - false), + /*VariablyModified=*/false, + NNS->containsUnexpandedParameterPack()), NNS(NNS), Name(Name), NumArgs(NumArgs) { assert(NNS && NNS->isDependent() && "DependentTemplateSpecializatonType requires dependent qualifier"); - for (unsigned I = 0; I != NumArgs; ++I) + for (unsigned I = 0; I != NumArgs; ++I) { + if (Args[I].containsUnexpandedParameterPack()) + setContainsUnexpandedParameterPack(); + new (&getArgBuffer()[I]) TemplateArgument(Args[I]); + } } void @@ -1052,6 +1106,7 @@ FunctionProtoType::FunctionProtoType(QualType Result, const QualType *ArgArray, : FunctionType(FunctionProto, Result, isVariadic, typeQuals, Canonical, Result->isDependentType(), Result->isVariablyModifiedType(), + Result->containsUnexpandedParameterPack(), Info), NumArgs(numArgs), NumExceptions(numExs), HasExceptionSpec(hasExs), AnyExceptionSpec(hasAnyExs) @@ -1061,7 +1116,10 @@ FunctionProtoType::FunctionProtoType(QualType Result, const QualType *ArgArray, for (unsigned i = 0; i != numArgs; ++i) { if (ArgArray[i]->isDependentType()) setDependent(); - + + if (ArgArray[i]->containsUnexpandedParameterPack()) + setContainsUnexpandedParameterPack(); + ArgInfo[i] = ArgArray[i]; } @@ -1106,7 +1164,9 @@ QualType TypedefType::desugar() const { TypeOfExprType::TypeOfExprType(Expr *E, QualType can) : Type(TypeOfExpr, can, E->isTypeDependent(), - E->getType()->isVariablyModifiedType()), TOExpr(E) { + E->getType()->isVariablyModifiedType(), + E->containsUnexpandedParameterPack()), + TOExpr(E) { } QualType TypeOfExprType::desugar() const { @@ -1120,7 +1180,9 @@ void DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID, DecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can) : Type(Decltype, can, E->isTypeDependent(), - E->getType()->isVariablyModifiedType()), E(E), + E->getType()->isVariablyModifiedType(), + E->containsUnexpandedParameterPack()), + E(E), UnderlyingType(underlyingType) { } @@ -1133,7 +1195,8 @@ void DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID, } TagType::TagType(TypeClass TC, const TagDecl *D, QualType can) - : Type(TC, can, D->isDependentType(), /*VariablyModified=*/false), + : Type(TC, can, D->isDependentType(), /*VariablyModified=*/false, + /*ContainsUnexpandedParameterPack=*/false), decl(const_cast<TagDecl*>(D)) {} static TagDecl *getInterestingTagDecl(TagDecl *decl) { @@ -1233,7 +1296,8 @@ TemplateSpecializationType(TemplateName T, unsigned NumArgs, QualType Canon) : Type(TemplateSpecialization, Canon.isNull()? QualType(this, 0) : Canon, - T.isDependent(), false), + T.isDependent(), false, + T.containsUnexpandedParameterPack()), Template(T), NumArgs(NumArgs) { assert((!Canon.isNull() || @@ -1249,7 +1313,9 @@ TemplateSpecializationType(TemplateName T, if (Args[Arg].getKind() == TemplateArgument::Type && Args[Arg].getAsType()->isVariablyModifiedType()) setVariablyModified(); - + if (Args[Arg].containsUnexpandedParameterPack()) + setContainsUnexpandedParameterPack(); + new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]); } } |