diff options
| author | Douglas Gregor <dgregor@apple.com> | 2011-01-14 17:12:22 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2011-01-14 17:12:22 +0000 |
| commit | 9f40713ebcbf2793e35f85d7cd76e44b11a7c78b (patch) | |
| tree | 46bb6ec1586a99998d650b60670856e707f39581 | |
| parent | 0dca5fdb4e039d0ae341814b7e5b2043a72acec0 (diff) | |
| download | bcm5719-llvm-9f40713ebcbf2793e35f85d7cd76e44b11a7c78b.tar.gz bcm5719-llvm-9f40713ebcbf2793e35f85d7cd76e44b11a7c78b.zip | |
When we're instantiating a direct variable initializer that has a pack
expansion in it, we may end up instantiating to an empty
expression-list. In this case, the variable is uninitialized; tweak
the instantiation logic to handle this case. Fixes PR8977.
llvm-svn: 123449
| -rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 12 | ||||
| -rw-r--r-- | clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp | 9 |
2 files changed, 15 insertions, 6 deletions
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 6b5713a2fa2..bd431a11386 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -314,19 +314,19 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) { ASTOwningVector<Expr*> InitArgs(SemaRef); if (!InstantiateInitializer(SemaRef, D->getInit(), TemplateArgs, LParenLoc, InitArgs, RParenLoc)) { - // Attach the initializer to the declaration. - if (D->hasCXXDirectInitializer()) { + // Attach the initializer to the declaration, if we have one. + if (InitArgs.size() == 0) + SemaRef.ActOnUninitializedDecl(Var, false); + else if (D->hasCXXDirectInitializer()) { // Add the direct initializer to the declaration. SemaRef.AddCXXDirectInitializerToDecl(Var, LParenLoc, move_arg(InitArgs), RParenLoc); - } else if (InitArgs.size() == 1) { + } else { + assert(InitArgs.size() == 1); Expr *Init = InitArgs.take()[0]; SemaRef.AddInitializerToDecl(Var, Init, false); - } else { - assert(InitArgs.size() == 0); - SemaRef.ActOnUninitializedDecl(Var, false); } } else { // FIXME: Not too happy about invalidating the declaration diff --git a/clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp b/clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp index b865d51411e..e2fa1229372 100644 --- a/clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp +++ b/clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp @@ -34,6 +34,15 @@ void initializer_list_expansion() { template void initializer_list_expansion<1, 2, 3, 4, 5>(); template void initializer_list_expansion<1, 2, 3, 4, 5, 6>(); // expected-note{{in instantiation of function template specialization 'initializer_list_expansion<1, 2, 3, 4, 5, 6>' requested here}} +namespace PR8977 { + struct A { }; + template<typename T, typename... Args> void f(Args... args) { + T t(args...); + }; + + template void f<A>(); +} + // In a base-specifier-list (Clause 10); the pattern is a base-specifier. template<typename ...Mixins> struct HasMixins : public Mixins... { |

