From aaf9f44a0d006d13bcbc91dd9718d269cfa3682c Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 4 Feb 2016 22:54:41 +0000 Subject: [PATCH] PR25271: When attaching default template arguments to redeclarations of a template, keep looking for default arguments if we see a template parameter pack. There may be default arguments preceding a pack with no default argument. Patch by Jannis Harder! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259836 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Serialization/ASTReaderDecl.cpp | 2 ++ ...variadic-templates-with-default-params.cpp | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 test/PCH/cxx-variadic-templates-with-default-params.cpp diff --git a/lib/Serialization/ASTReaderDecl.cpp b/lib/Serialization/ASTReaderDecl.cpp index 9bcd9a0164..b249da9946 100644 --- a/lib/Serialization/ASTReaderDecl.cpp +++ b/lib/Serialization/ASTReaderDecl.cpp @@ -3016,6 +3016,8 @@ static void inheritDefaultTemplateArguments(ASTContext &Context, for (unsigned I = 0, N = FromTP->size(); I != N; ++I) { NamedDecl *FromParam = FromTP->getParam(N - I - 1); + if (FromParam->isParameterPack()) + continue; NamedDecl *ToParam = ToTP->getParam(N - I - 1); if (auto *FTTP = dyn_cast(FromParam)) { diff --git a/test/PCH/cxx-variadic-templates-with-default-params.cpp b/test/PCH/cxx-variadic-templates-with-default-params.cpp new file mode 100644 index 0000000000..2c1482091d --- /dev/null +++ b/test/PCH/cxx-variadic-templates-with-default-params.cpp @@ -0,0 +1,26 @@ +// Test this without pch. +// RUN: %clang_cc1 -std=c++11 -include %s -fsyntax-only -verify %s + +// Test with pch. +// RUN: %clang_cc1 -std=c++11 -x c++-header -emit-pch -o %t %s +// RUN: %clang_cc1 -std=c++11 -include-pch %t -fsyntax-only -verify %s + +// expected-no-diagnostics + +// PR25271: Ensure that default template arguments prior to a parameter pack +// successfully round-trip. +#ifndef HEADER +#define HEADER +template +class dummy; + +template +class dummy { + int field[T]; +}; +#else +void f() { + dummy<> x; + (void)x; +} +#endif -- 2.50.1