summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/tools/clang/lib/Sema/SemaTemplateVariadic.cpp
diff options
context:
space:
mode:
authorpatrick <patrick@openbsd.org>2019-01-27 16:42:12 +0000
committerpatrick <patrick@openbsd.org>2019-01-27 16:42:12 +0000
commitb773203fb58f3ef282fb69c832d8710cab5bc82d (patch)
treee75913f147570fbd75169647b144df85b88a038c /gnu/llvm/tools/clang/lib/Sema/SemaTemplateVariadic.cpp
parenttweak errno in previous (diff)
downloadwireguard-openbsd-b773203fb58f3ef282fb69c832d8710cab5bc82d.tar.xz
wireguard-openbsd-b773203fb58f3ef282fb69c832d8710cab5bc82d.zip
Import LLVM 7.0.1 release including clang, lld and lldb.
Diffstat (limited to 'gnu/llvm/tools/clang/lib/Sema/SemaTemplateVariadic.cpp')
-rw-r--r--gnu/llvm/tools/clang/lib/Sema/SemaTemplateVariadic.cpp233
1 files changed, 131 insertions, 102 deletions
diff --git a/gnu/llvm/tools/clang/lib/Sema/SemaTemplateVariadic.cpp b/gnu/llvm/tools/clang/lib/Sema/SemaTemplateVariadic.cpp
index d81837dad50..6f9dddf5c05 100644
--- a/gnu/llvm/tools/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/gnu/llvm/tools/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -26,23 +26,10 @@ using namespace clang;
// Visitor that collects unexpanded parameter packs
//----------------------------------------------------------------------------
-/// \brief Retrieve the depth and index of a parameter pack.
-static std::pair<unsigned, unsigned>
-getDepthAndIndex(NamedDecl *ND) {
- if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(ND))
- return std::make_pair(TTP->getDepth(), TTP->getIndex());
-
- if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(ND))
- return std::make_pair(NTTP->getDepth(), NTTP->getIndex());
-
- TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(ND);
- return std::make_pair(TTP->getDepth(), TTP->getIndex());
-}
-
namespace {
- /// \brief A class that collects unexpanded parameter packs.
+ /// A class that collects unexpanded parameter packs.
class CollectUnexpandedParameterPacksVisitor :
- public RecursiveASTVisitor<CollectUnexpandedParameterPacksVisitor>
+ public RecursiveASTVisitor<CollectUnexpandedParameterPacksVisitor>
{
typedef RecursiveASTVisitor<CollectUnexpandedParameterPacksVisitor>
inherited;
@@ -71,7 +58,7 @@ namespace {
if (T->getDepth() < DepthLimit)
Unexpanded.push_back({T, Loc});
}
-
+
public:
explicit CollectUnexpandedParameterPacksVisitor(
SmallVectorImpl<UnexpandedParameterPack> &Unexpanded)
@@ -83,14 +70,14 @@ namespace {
// Recording occurrences of (unexpanded) parameter packs.
//------------------------------------------------------------------------
- /// \brief Record occurrences of template type parameter packs.
+ /// Record occurrences of template type parameter packs.
bool VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) {
if (TL.getTypePtr()->isParameterPack())
addUnexpanded(TL.getTypePtr(), TL.getNameLoc());
return true;
}
- /// \brief Record occurrences of template type parameter packs
+ /// Record occurrences of template type parameter packs
/// when we don't have proper source-location information for
/// them.
///
@@ -102,27 +89,27 @@ namespace {
return true;
}
- /// \brief Record occurrences of function and non-type template
+ /// Record occurrences of function and non-type template
/// parameter packs in an expression.
bool VisitDeclRefExpr(DeclRefExpr *E) {
if (E->getDecl()->isParameterPack())
addUnexpanded(E->getDecl(), E->getLocation());
-
+
return true;
}
-
- /// \brief Record occurrences of template template parameter packs.
+
+ /// Record occurrences of template template parameter packs.
bool TraverseTemplateName(TemplateName Template) {
if (auto *TTP = dyn_cast_or_null<TemplateTemplateParmDecl>(
Template.getAsTemplateDecl())) {
if (TTP->isParameterPack())
addUnexpanded(TTP);
}
-
+
return inherited::TraverseTemplateName(Template);
}
- /// \brief Suppress traversal into Objective-C container literal
+ /// Suppress traversal into Objective-C container literal
/// elements that are pack expansions.
bool TraverseObjCDictionaryLiteral(ObjCDictionaryLiteral *E) {
if (!E->containsUnexpandedParameterPack())
@@ -142,9 +129,9 @@ namespace {
// Pruning the search for unexpanded parameter packs.
//------------------------------------------------------------------------
- /// \brief Suppress traversal into statements and expressions that
+ /// Suppress traversal into statements and expressions that
/// do not contain unexpanded parameter packs.
- bool TraverseStmt(Stmt *S) {
+ bool TraverseStmt(Stmt *S) {
Expr *E = dyn_cast_or_null<Expr>(S);
if ((E && E->containsUnexpandedParameterPack()) || InLambda)
return inherited::TraverseStmt(S);
@@ -152,7 +139,7 @@ namespace {
return true;
}
- /// \brief Suppress traversal into types that do not contain
+ /// Suppress traversal into types that do not contain
/// unexpanded parameter packs.
bool TraverseType(QualType T) {
if ((!T.isNull() && T->containsUnexpandedParameterPack()) || InLambda)
@@ -161,10 +148,10 @@ namespace {
return true;
}
- /// \brief Suppress traversal into types with location information
+ /// Suppress traversal into types with location information
/// that do not contain unexpanded parameter packs.
bool TraverseTypeLoc(TypeLoc TL) {
- if ((!TL.getType().isNull() &&
+ if ((!TL.getType().isNull() &&
TL.getType()->containsUnexpandedParameterPack()) ||
InLambda)
return inherited::TraverseTypeLoc(TL);
@@ -172,8 +159,8 @@ namespace {
return true;
}
- /// \brief Suppress traversal of parameter packs.
- bool TraverseDecl(Decl *D) {
+ /// Suppress traversal of parameter packs.
+ bool TraverseDecl(Decl *D) {
// A function parameter pack is a pack expansion, so cannot contain
// an unexpanded parameter pack. Likewise for a template parameter
// pack that contains any references to other packs.
@@ -183,7 +170,7 @@ namespace {
return inherited::TraverseDecl(D);
}
- /// \brief Suppress traversal of pack-expanded attributes.
+ /// Suppress traversal of pack-expanded attributes.
bool TraverseAttr(Attr *A) {
if (A->isPackExpansion())
return true;
@@ -191,7 +178,7 @@ namespace {
return inherited::TraverseAttr(A);
}
- /// \brief Suppress traversal of pack expansion expressions and types.
+ /// Suppress traversal of pack expansion expressions and types.
///@{
bool TraversePackExpansionType(PackExpansionType *T) { return true; }
bool TraversePackExpansionTypeLoc(PackExpansionTypeLoc TL) { return true; }
@@ -200,7 +187,7 @@ namespace {
///@}
- /// \brief Suppress traversal of using-declaration pack expansion.
+ /// Suppress traversal of using-declaration pack expansion.
bool TraverseUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
if (D->isPackExpansion())
return true;
@@ -208,7 +195,7 @@ namespace {
return inherited::TraverseUnresolvedUsingValueDecl(D);
}
- /// \brief Suppress traversal of using-declaration pack expansion.
+ /// Suppress traversal of using-declaration pack expansion.
bool TraverseUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D) {
if (D->isPackExpansion())
return true;
@@ -216,7 +203,7 @@ namespace {
return inherited::TraverseUnresolvedUsingTypenameDecl(D);
}
- /// \brief Suppress traversal of template argument pack expansions.
+ /// Suppress traversal of template argument pack expansions.
bool TraverseTemplateArgument(const TemplateArgument &Arg) {
if (Arg.isPackExpansion())
return true;
@@ -224,15 +211,15 @@ namespace {
return inherited::TraverseTemplateArgument(Arg);
}
- /// \brief Suppress traversal of template argument pack expansions.
+ /// Suppress traversal of template argument pack expansions.
bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &ArgLoc) {
if (ArgLoc.getArgument().isPackExpansion())
return true;
-
+
return inherited::TraverseTemplateArgumentLoc(ArgLoc);
}
- /// \brief Suppress traversal of base specifier pack expansions.
+ /// Suppress traversal of base specifier pack expansions.
bool TraverseCXXBaseSpecifier(const CXXBaseSpecifier &Base) {
if (Base.isPackExpansion())
return true;
@@ -240,7 +227,7 @@ namespace {
return inherited::TraverseCXXBaseSpecifier(Base);
}
- /// \brief Suppress traversal of mem-initializer pack expansions.
+ /// Suppress traversal of mem-initializer pack expansions.
bool TraverseConstructorInitializer(CXXCtorInitializer *Init) {
if (Init->isPackExpansion())
return true;
@@ -248,7 +235,7 @@ namespace {
return inherited::TraverseConstructorInitializer(Init);
}
- /// \brief Note whether we're traversing a lambda containing an unexpanded
+ /// Note whether we're traversing a lambda containing an unexpanded
/// parameter pack. In this case, the unexpanded pack can occur anywhere,
/// including all the places where we normally wouldn't look. Within a
/// lambda, we don't propagate the 'contains unexpanded parameter pack' bit
@@ -284,7 +271,7 @@ namespace {
};
}
-/// \brief Determine whether it's possible for an unexpanded parameter pack to
+/// Determine whether it's possible for an unexpanded parameter pack to
/// be valid in this location. This only happens when we're in a declaration
/// that is nested within an expression that could be expanded, such as a
/// lambda-expression within a function call.
@@ -298,7 +285,7 @@ bool Sema::isUnexpandedParameterPackPermitted() {
return false;
}
-/// \brief Diagnose all of the unexpanded parameter packs in the given
+/// Diagnose all of the unexpanded parameter packs in the given
/// vector.
bool
Sema::DiagnoseUnexpandedParameterPacks(SourceLocation Loc,
@@ -314,8 +301,18 @@ Sema::DiagnoseUnexpandedParameterPacks(SourceLocation Loc,
// later.
SmallVector<UnexpandedParameterPack, 4> LambdaParamPackReferences;
for (unsigned N = FunctionScopes.size(); N; --N) {
- if (sema::LambdaScopeInfo *LSI =
- dyn_cast<sema::LambdaScopeInfo>(FunctionScopes[N-1])) {
+ sema::FunctionScopeInfo *Func = FunctionScopes[N-1];
+ // We do not permit pack expansion that would duplicate a statement
+ // expression, not even within a lambda.
+ // FIXME: We could probably support this for statement expressions that do
+ // not contain labels, and for pack expansions that expand both the stmt
+ // expr and the enclosing lambda.
+ if (std::any_of(
+ Func->CompoundScopes.begin(), Func->CompoundScopes.end(),
+ [](sema::CompoundScopeInfo &CSI) { return CSI.IsStmtExpr; }))
+ break;
+
+ if (auto *LSI = dyn_cast<sema::LambdaScopeInfo>(Func)) {
if (N == FunctionScopes.size()) {
for (auto &Param : Unexpanded) {
auto *PD = dyn_cast_or_null<ParmVarDecl>(
@@ -338,7 +335,7 @@ Sema::DiagnoseUnexpandedParameterPacks(SourceLocation Loc,
return false;
}
}
-
+
SmallVector<SourceLocation, 4> Locations;
SmallVector<IdentifierInfo *, 4> Names;
llvm::SmallPtrSet<IdentifierInfo *, 4> NamesKnown;
@@ -368,11 +365,11 @@ Sema::DiagnoseUnexpandedParameterPacks(SourceLocation Loc,
return true;
}
-bool Sema::DiagnoseUnexpandedParameterPack(SourceLocation Loc,
+bool Sema::DiagnoseUnexpandedParameterPack(SourceLocation Loc,
TypeSourceInfo *T,
UnexpandedParameterPackContext UPPC) {
// C++0x [temp.variadic]p5:
- // An appearance of a name of a parameter pack that is not expanded is
+ // An appearance of a name of a parameter pack that is not expanded is
// ill-formed.
if (!T->getType()->containsUnexpandedParameterPack())
return false;
@@ -387,7 +384,7 @@ bool Sema::DiagnoseUnexpandedParameterPack(SourceLocation Loc,
bool Sema::DiagnoseUnexpandedParameterPack(Expr *E,
UnexpandedParameterPackContext UPPC) {
// C++0x [temp.variadic]p5:
- // An appearance of a name of a parameter pack that is not expanded is
+ // An appearance of a name of a parameter pack that is not expanded is
// ill-formed.
if (!E->containsUnexpandedParameterPack())
return false;
@@ -401,9 +398,9 @@ bool Sema::DiagnoseUnexpandedParameterPack(Expr *E,
bool Sema::DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS,
UnexpandedParameterPackContext UPPC) {
// C++0x [temp.variadic]p5:
- // An appearance of a name of a parameter pack that is not expanded is
+ // An appearance of a name of a parameter pack that is not expanded is
// ill-formed.
- if (!SS.getScopeRep() ||
+ if (!SS.getScopeRep() ||
!SS.getScopeRep()->containsUnexpandedParameterPack())
return false;
@@ -418,7 +415,7 @@ bool Sema::DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS,
bool Sema::DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo,
UnexpandedParameterPackContext UPPC) {
// C++0x [temp.variadic]p5:
- // An appearance of a name of a parameter pack that is not expanded is
+ // An appearance of a name of a parameter pack that is not expanded is
// ill-formed.
switch (NameInfo.getName().getNameKind()) {
case DeclarationName::Identifier:
@@ -454,7 +451,7 @@ bool Sema::DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo,
bool Sema::DiagnoseUnexpandedParameterPack(SourceLocation Loc,
TemplateName Template,
UnexpandedParameterPackContext UPPC) {
-
+
if (Template.isNull() || !Template.containsUnexpandedParameterPack())
return false;
@@ -467,10 +464,10 @@ bool Sema::DiagnoseUnexpandedParameterPack(SourceLocation Loc,
bool Sema::DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg,
UnexpandedParameterPackContext UPPC) {
- if (Arg.getArgument().isNull() ||
+ if (Arg.getArgument().isNull() ||
!Arg.getArgument().containsUnexpandedParameterPack())
return false;
-
+
SmallVector<UnexpandedParameterPack, 2> Unexpanded;
CollectUnexpandedParameterPacksVisitor(Unexpanded)
.TraverseTemplateArgumentLoc(Arg);
@@ -492,12 +489,12 @@ void Sema::collectUnexpandedParameterPacks(TemplateArgumentLoc Arg,
void Sema::collectUnexpandedParameterPacks(QualType T,
SmallVectorImpl<UnexpandedParameterPack> &Unexpanded) {
- CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(T);
-}
+ CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseType(T);
+}
void Sema::collectUnexpandedParameterPacks(TypeLoc TL,
SmallVectorImpl<UnexpandedParameterPack> &Unexpanded) {
- CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(TL);
+ CollectUnexpandedParameterPacksVisitor(Unexpanded).TraverseTypeLoc(TL);
}
void Sema::collectUnexpandedParameterPacks(
@@ -515,7 +512,7 @@ void Sema::collectUnexpandedParameterPacks(
}
-ParsedTemplateArgument
+ParsedTemplateArgument
Sema::ActOnPackExpansion(const ParsedTemplateArgument &Arg,
SourceLocation EllipsisLoc) {
if (Arg.isInvalid())
@@ -527,7 +524,7 @@ Sema::ActOnPackExpansion(const ParsedTemplateArgument &Arg,
if (Result.isInvalid())
return ParsedTemplateArgument();
- return ParsedTemplateArgument(Arg.getKind(), Result.get().getAsOpaquePtr(),
+ return ParsedTemplateArgument(Arg.getKind(), Result.get().getAsOpaquePtr(),
Arg.getLocation());
}
@@ -535,11 +532,11 @@ Sema::ActOnPackExpansion(const ParsedTemplateArgument &Arg,
ExprResult Result = ActOnPackExpansion(Arg.getAsExpr(), EllipsisLoc);
if (Result.isInvalid())
return ParsedTemplateArgument();
-
- return ParsedTemplateArgument(Arg.getKind(), Result.get(),
+
+ return ParsedTemplateArgument(Arg.getKind(), Result.get(),
Arg.getLocation());
}
-
+
case ParsedTemplateArgument::Template:
if (!Arg.getAsTemplate().get().containsUnexpandedParameterPack()) {
SourceRange R(Arg.getLocation());
@@ -549,13 +546,13 @@ Sema::ActOnPackExpansion(const ParsedTemplateArgument &Arg,
<< R;
return ParsedTemplateArgument();
}
-
+
return Arg.getTemplatePackExpansion(EllipsisLoc);
}
llvm_unreachable("Unhandled template argument kind?");
}
-TypeResult Sema::ActOnPackExpansion(ParsedType Type,
+TypeResult Sema::ActOnPackExpansion(ParsedType Type,
SourceLocation EllipsisLoc) {
TypeSourceInfo *TSInfo;
GetTypeFromParser(Type, &TSInfo);
@@ -565,7 +562,7 @@ TypeResult Sema::ActOnPackExpansion(ParsedType Type,
TypeSourceInfo *TSResult = CheckPackExpansion(TSInfo, EllipsisLoc, None);
if (!TSResult)
return true;
-
+
return CreateParsedType(TSResult->getType(), TSResult);
}
@@ -573,7 +570,7 @@ TypeSourceInfo *
Sema::CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc,
Optional<unsigned> NumExpansions) {
// Create the pack expansion type and source-location information.
- QualType Result = CheckPackExpansion(Pattern->getType(),
+ QualType Result = CheckPackExpansion(Pattern->getType(),
Pattern->getTypeLoc().getSourceRange(),
EllipsisLoc, NumExpansions);
if (Result.isNull())
@@ -611,7 +608,7 @@ ExprResult Sema::CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
Optional<unsigned> NumExpansions) {
if (!Pattern)
return ExprError();
-
+
// C++0x [temp.variadic]p5:
// The pattern of a pack expansion shall name one or more
// parameter packs that are not expanded by a nested pack
@@ -621,7 +618,7 @@ ExprResult Sema::CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
<< Pattern->getSourceRange();
return ExprError();
}
-
+
// Create the pack expansion expression and source-location information.
return new (Context)
PackExpansionExpr(Context.DependentTy, Pattern, EllipsisLoc, NumExpansions);
@@ -636,7 +633,9 @@ bool Sema::CheckParameterPacksForExpansion(
RetainExpansion = false;
std::pair<IdentifierInfo *, SourceLocation> FirstPack;
bool HaveFirstPack = false;
-
+ Optional<unsigned> NumPartialExpansions;
+ SourceLocation PartiallySubstitutedPackLoc;
+
for (ArrayRef<UnexpandedParameterPack>::iterator i = Unexpanded.begin(),
end = Unexpanded.end();
i != end; ++i) {
@@ -644,7 +643,7 @@ bool Sema::CheckParameterPacksForExpansion(
unsigned Depth = 0, Index = 0;
IdentifierInfo *Name;
bool IsFunctionParameterPack = false;
-
+
if (const TemplateTypeParmType *TTP
= i->first.dyn_cast<const TemplateTypeParmType *>()) {
Depth = TTP->getDepth();
@@ -659,13 +658,13 @@ bool Sema::CheckParameterPacksForExpansion(
Name = ND->getIdentifier();
}
-
+
// Determine the size of this argument pack.
- unsigned NewPackSize;
+ unsigned NewPackSize;
if (IsFunctionParameterPack) {
// Figure out whether we're instantiating to an argument pack or not.
typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
-
+
llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation
= CurrentInstantiationScope->findInstantiationOf(
i->first.get<NamedDecl *>());
@@ -679,35 +678,40 @@ bool Sema::CheckParameterPacksForExpansion(
continue;
}
} else {
- // If we don't have a template argument at this depth/index, then we
- // cannot expand the pack expansion. Make a note of this, but we still
+ // If we don't have a template argument at this depth/index, then we
+ // cannot expand the pack expansion. Make a note of this, but we still
// want to check any parameter packs we *do* have arguments for.
if (Depth >= TemplateArgs.getNumLevels() ||
!TemplateArgs.hasTemplateArgument(Depth, Index)) {
ShouldExpand = false;
continue;
}
-
+
// Determine the size of the argument pack.
NewPackSize = TemplateArgs(Depth, Index).pack_size();
}
-
+
// C++0x [temp.arg.explicit]p9:
- // Template argument deduction can extend the sequence of template
+ // Template argument deduction can extend the sequence of template
// arguments corresponding to a template parameter pack, even when the
// sequence contains explicitly specified template arguments.
if (!IsFunctionParameterPack && CurrentInstantiationScope) {
- if (NamedDecl *PartialPack
+ if (NamedDecl *PartialPack
= CurrentInstantiationScope->getPartiallySubstitutedPack()){
unsigned PartialDepth, PartialIndex;
std::tie(PartialDepth, PartialIndex) = getDepthAndIndex(PartialPack);
- if (PartialDepth == Depth && PartialIndex == Index)
+ if (PartialDepth == Depth && PartialIndex == Index) {
RetainExpansion = true;
+ // We don't actually know the new pack size yet.
+ NumPartialExpansions = NewPackSize;
+ PartiallySubstitutedPackLoc = i->second;
+ continue;
+ }
}
}
-
+
if (!NumExpansions) {
- // The is the first pack we've seen for which we have an argument.
+ // The is the first pack we've seen for which we have an argument.
// Record it.
NumExpansions = NewPackSize;
FirstPack.first = Name;
@@ -715,10 +719,10 @@ bool Sema::CheckParameterPacksForExpansion(
HaveFirstPack = true;
continue;
}
-
+
if (NewPackSize != *NumExpansions) {
// C++0x [temp.variadic]p5:
- // All of the parameter packs expanded by a pack expansion shall have
+ // All of the parameter packs expanded by a pack expansion shall have
// the same number of arguments specified.
if (HaveFirstPack)
Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict)
@@ -732,6 +736,28 @@ bool Sema::CheckParameterPacksForExpansion(
}
}
+ // If we're performing a partial expansion but we also have a full expansion,
+ // expand to the number of common arguments. For example, given:
+ //
+ // template<typename ...T> struct A {
+ // template<typename ...U> void f(pair<T, U>...);
+ // };
+ //
+ // ... a call to 'A<int, int>().f<int>' should expand the pack once and
+ // retain an expansion.
+ if (NumPartialExpansions) {
+ if (NumExpansions && *NumExpansions < *NumPartialExpansions) {
+ NamedDecl *PartialPack =
+ CurrentInstantiationScope->getPartiallySubstitutedPack();
+ Diag(EllipsisLoc, diag::err_pack_expansion_length_conflict_partial)
+ << PartialPack << *NumPartialExpansions << *NumExpansions
+ << SourceRange(PartiallySubstitutedPackLoc);
+ return true;
+ }
+
+ NumExpansions = NumPartialExpansions;
+ }
+
return false;
}
@@ -746,17 +772,17 @@ Optional<unsigned> Sema::getNumArgumentsInExpansion(QualType T,
// Compute the depth and index for this parameter pack.
unsigned Depth;
unsigned Index;
-
+
if (const TemplateTypeParmType *TTP
= Unexpanded[I].first.dyn_cast<const TemplateTypeParmType *>()) {
Depth = TTP->getDepth();
Index = TTP->getIndex();
- } else {
+ } else {
NamedDecl *ND = Unexpanded[I].first.get<NamedDecl *>();
if (isa<ParmVarDecl>(ND)) {
// Function parameter pack.
typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
-
+
llvm::PointerUnion<Decl *, DeclArgumentPack *> *Instantiation
= CurrentInstantiationScope->findInstantiationOf(
Unexpanded[I].first.get<NamedDecl *>());
@@ -778,13 +804,13 @@ Optional<unsigned> Sema::getNumArgumentsInExpansion(QualType T,
// The pattern refers to an unknown template argument. We're not ready to
// expand this pack yet.
return None;
-
+
// Determine the size of the argument pack.
unsigned Size = TemplateArgs(Depth, Index).pack_size();
assert((!Result || *Result == Size) && "inconsistent pack sizes");
Result = Size;
}
-
+
return Result;
}
@@ -800,18 +826,19 @@ bool Sema::containsUnexpandedParameterPacks(Declarator &D) {
return true;
break;
}
-
+
case TST_typeofExpr:
case TST_decltype:
- if (DS.getRepAsExpr() &&
+ if (DS.getRepAsExpr() &&
DS.getRepAsExpr()->containsUnexpandedParameterPack())
return true;
break;
-
+
case TST_unspecified:
case TST_void:
case TST_char:
case TST_wchar:
+ case TST_char8:
case TST_char16:
case TST_char32:
case TST_int:
@@ -819,6 +846,8 @@ bool Sema::containsUnexpandedParameterPacks(Declarator &D) {
case TST_half:
case TST_float:
case TST_double:
+ case TST_Accum:
+ case TST_Fract:
case TST_Float16:
case TST_float128:
case TST_bool:
@@ -850,7 +879,7 @@ bool Sema::containsUnexpandedParameterPacks(Declarator &D) {
case DeclaratorChunk::BlockPointer:
// These declarator chunks cannot contain any parameter packs.
break;
-
+
case DeclaratorChunk::Array:
if (Chunk.Arr.NumElts &&
Chunk.Arr.NumElts->containsUnexpandedParameterPack())
@@ -871,14 +900,14 @@ bool Sema::containsUnexpandedParameterPacks(Declarator &D) {
->containsUnexpandedParameterPack())
return true;
}
- } else if (Chunk.Fun.getExceptionSpecType() == EST_ComputedNoexcept &&
+ } else if (isComputedNoexcept(Chunk.Fun.getExceptionSpecType()) &&
Chunk.Fun.NoexceptExpr->containsUnexpandedParameterPack())
return true;
if (Chunk.Fun.hasTrailingReturnType()) {
QualType T = Chunk.Fun.getTrailingReturnType().get();
- if (!T.isNull() && T->containsUnexpandedParameterPack())
- return true;
+ if (!T.isNull() && T->containsUnexpandedParameterPack())
+ return true;
}
break;
@@ -889,7 +918,7 @@ bool Sema::containsUnexpandedParameterPacks(Declarator &D) {
break;
}
}
-
+
return false;
}
@@ -906,7 +935,7 @@ class ParameterPackValidatorCCC : public CorrectionCandidateCallback {
}
-/// \brief Called when an expression computing the size of a parameter pack
+/// Called when an expression computing the size of a parameter pack
/// is parsed.
///
/// \code
@@ -935,7 +964,7 @@ ExprResult Sema::ActOnSizeofParameterPackExpr(Scope *S,
case LookupResult::Found:
ParameterPack = R.getFoundDecl();
break;
-
+
case LookupResult::NotFound:
case LookupResult::NotFoundInCurrentInstantiation:
if (TypoCorrection Corrected =
@@ -951,12 +980,12 @@ ExprResult Sema::ActOnSizeofParameterPackExpr(Scope *S,
case LookupResult::FoundOverloaded:
case LookupResult::FoundUnresolvedValue:
break;
-
+
case LookupResult::Ambiguous:
DiagnoseAmbiguousLookup(R);
return ExprError();
}
-
+
if (!ParameterPack || !ParameterPack->isParameterPack()) {
Diag(NameLoc, diag::err_sizeof_pack_no_pack_name)
<< &Name;