From 3c6bd2ad386590ffcaa65e49a36e7976be82062d Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 5 Jan 2011 21:11:38 +0000 Subject: [PATCH] Add Decl::isParameterPack(), which covers both function and template parameter packs, along with ParmVarDecl::isParameterPack(), which looks for function parameter packs. Use these routines to fix some obvious FIXMEs. llvm-svn: 122904 --- clang/include/clang/AST/Decl.h | 4 ++++ clang/include/clang/AST/DeclBase.h | 3 +++ clang/lib/AST/Decl.cpp | 4 ++++ clang/lib/AST/DeclBase.cpp | 7 +++++++ clang/lib/AST/Expr.cpp | 7 ++----- clang/lib/Sema/SemaTemplateVariadic.cpp | 6 ++---- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index c8c685a15673..679e809ac9a0 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -1133,6 +1133,10 @@ public: return getType(); } + /// \brief Determine whether this parameter is actually a function + /// parameter pack. + bool isParameterPack() const; + /// setOwningFunction - Sets the function declaration that owns this /// ParmVarDecl. Since ParmVarDecls are often created before the /// FunctionDecls that own them, this routine is required to update diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h index f091ce043adc..e99d54771ab6 100644 --- a/clang/include/clang/AST/DeclBase.h +++ b/clang/include/clang/AST/DeclBase.h @@ -567,6 +567,9 @@ public: /// template parameter pack. bool isTemplateParameterPack() const; + /// \brief Whether this declaration is a parameter pack. + bool isParameterPack() const; + /// \brief Whether this declaration is a function or function template. bool isFunctionOrFunctionTemplate() const; diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 5b82ddd7c69f..c51d2cdc37cc 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -1221,6 +1221,10 @@ SourceRange ParmVarDecl::getDefaultArgRange() const { return SourceRange(); } +bool ParmVarDecl::isParameterPack() const { + return isa(getType()); +} + //===----------------------------------------------------------------------===// // FunctionDecl Implementation //===----------------------------------------------------------------------===// diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 700100507b46..e16bd22f3365 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -119,6 +119,13 @@ bool Decl::isTemplateParameterPack() const { return false; } +bool Decl::isParameterPack() const { + if (const ParmVarDecl *Parm = dyn_cast(this)) + return Parm->isParameterPack(); + + return isTemplateParameterPack(); +} + bool Decl::isFunctionOrFunctionTemplate() const { if (const UsingShadowDecl *UD = dyn_cast(this)) return UD->getTargetDecl()->isFunctionOrFunctionTemplate(); diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 3a71883419f3..c1dc5326e59c 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -211,11 +211,8 @@ void DeclRefExpr::computeDependence() { // Determine whether this expression contains any unexpanded parameter // packs. // Is the declaration a parameter pack? - if (NonTypeTemplateParmDecl *NTTP = dyn_cast(D)) { - if (NTTP->isParameterPack()) - ExprBits.ContainsUnexpandedParameterPack = true; - } - // FIXME: Variadic templates function parameter packs. + if (D->isParameterPack()) + ExprBits.ContainsUnexpandedParameterPack = true; } DeclRefExpr::DeclRefExpr(NestedNameSpecifier *Qualifier, diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp b/clang/lib/Sema/SemaTemplateVariadic.cpp index fb88bd114b4f..3090d1532dfb 100644 --- a/clang/lib/Sema/SemaTemplateVariadic.cpp +++ b/clang/lib/Sema/SemaTemplateVariadic.cpp @@ -602,9 +602,8 @@ ExprResult Sema::ActOnSizeofParameterPackExpr(Scope *S, case LookupResult::NotFoundInCurrentInstantiation: if (DeclarationName CorrectedName = CorrectTypo(R, S, 0, 0, false, CTC_NoKeywords)) { - // FIXME: Variadic templates function parameter packs. if (NamedDecl *CorrectedResult = R.getAsSingle()) - if (CorrectedResult->isTemplateParameterPack()) { + if (CorrectedResult->isParameterPack()) { ParameterPack = CorrectedResult; Diag(NameLoc, diag::err_sizeof_pack_no_pack_name_suggest) << &Name << CorrectedName @@ -624,8 +623,7 @@ ExprResult Sema::ActOnSizeofParameterPackExpr(Scope *S, return ExprError(); } - // FIXME: Variadic templates function parameter packs. - if (!ParameterPack || !ParameterPack->isTemplateParameterPack()) { + if (!ParameterPack || !ParameterPack->isParameterPack()) { Diag(NameLoc, diag::err_sizeof_pack_no_pack_name) << &Name; return ExprError();