PR25271: When attaching default template arguments to redeclarations of a
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 4 Feb 2016 22:54:41 +0000 (22:54 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 4 Feb 2016 22:54:41 +0000 (22:54 +0000)
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!

llvm-svn: 259836

clang/lib/Serialization/ASTReaderDecl.cpp
clang/test/PCH/cxx-variadic-templates-with-default-params.cpp [new file with mode: 0644]

index 9bcd9a0..b249da9 100644 (file)
@@ -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<TemplateTypeParmDecl>(FromParam)) {
diff --git a/clang/test/PCH/cxx-variadic-templates-with-default-params.cpp b/clang/test/PCH/cxx-variadic-templates-with-default-params.cpp
new file mode 100644 (file)
index 0000000..2c14820
--- /dev/null
@@ -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<unsigned T=123, unsigned... U>
+class dummy;
+
+template<unsigned T, unsigned... U>
+class dummy {
+    int field[T];
+};
+#else
+void f() {
+    dummy<> x;
+    (void)x;
+}
+#endif