diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-12-16 01:31:22 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-12-16 01:31:22 +0000 |
commit | a31040f16604849b3b1dc36015056c81bae68ad1 (patch) | |
tree | 7ba4ebf887f2c72419dc8f379eea4b9c4ff4e915 /lib/Sema | |
parent | 6ccab97c17c17f38eb92c7fe02c766508875bd97 (diff) |
Check for unexpanded parameter packs within variable initializers.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121938 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 45 | ||||
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 14 |
2 files changed, 38 insertions, 21 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index b46561851c..3f94bdc669 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4464,27 +4464,34 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) { return; } - // C++ [class.static.data]p4 - // If a static data member is of const integral or const - // enumeration type, its declaration in the class definition can - // specify a constant-initializer which shall be an integral - // constant expression (5.19). In that case, the member can appear - // in integral constant expressions. The member shall still be - // defined in a namespace scope if it is used in the program and the - // namespace scope definition shall not contain an initializer. - // - // We already performed a redefinition check above, but for static - // data members we also need to check whether there was an in-class - // declaration with an initializer. const VarDecl* PrevInit = 0; - if (VDecl->isStaticDataMember() && VDecl->getAnyInitializer(PrevInit)) { - Diag(VDecl->getLocation(), diag::err_redefinition) << VDecl->getDeclName(); - Diag(PrevInit->getLocation(), diag::note_previous_definition); - return; - } + if (getLangOptions().CPlusPlus) { + // C++ [class.static.data]p4 + // If a static data member is of const integral or const + // enumeration type, its declaration in the class definition can + // specify a constant-initializer which shall be an integral + // constant expression (5.19). In that case, the member can appear + // in integral constant expressions. The member shall still be + // defined in a namespace scope if it is used in the program and the + // namespace scope definition shall not contain an initializer. + // + // We already performed a redefinition check above, but for static + // data members we also need to check whether there was an in-class + // declaration with an initializer. + if (VDecl->isStaticDataMember() && VDecl->getAnyInitializer(PrevInit)) { + Diag(VDecl->getLocation(), diag::err_redefinition) << VDecl->getDeclName(); + Diag(PrevInit->getLocation(), diag::note_previous_definition); + return; + } - if (getLangOptions().CPlusPlus && VDecl->hasLocalStorage()) - getCurFunction()->setHasBranchProtectedScope(); + if (VDecl->hasLocalStorage()) + getCurFunction()->setHasBranchProtectedScope(); + + if (DiagnoseUnexpandedParameterPack(Init, UPPC_Initializer)) { + VDecl->setInvalidDecl(); + return; + } + } // Capture the variable that is being initialized and the style of // initialization. diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 0cf5f99b64..30e8b1e28e 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -5517,11 +5517,21 @@ void Sema::AddCXXDirectInitializerToDecl(Decl *RealDecl, return; } + bool IsDependent = false; + for (unsigned I = 0, N = Exprs.size(); I != N; ++I) { + if (DiagnoseUnexpandedParameterPack(Exprs.get()[I], UPPC_Expression)) { + VDecl->setInvalidDecl(); + return; + } + + if (Exprs.get()[I]->isTypeDependent()) + IsDependent = true; + } + // If either the declaration has a dependent type or if any of the // expressions is type-dependent, we represent the initialization // via a ParenListExpr for later use during template instantiation. - if (VDecl->getType()->isDependentType() || - Expr::hasAnyTypeDependentArguments((Expr **)Exprs.get(), Exprs.size())) { + if (VDecl->getType()->isDependentType() || IsDependent) { // Let clients know that initialization was done with a direct initializer. VDecl->setCXXDirectInitializer(true); |