[PATCH] D16148: Fix for PR25271: Ensure that variadic template parameter defaults PCH roundtrip

Jannis Harder via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 13 11:30:09 PST 2016


jix created this revision.
jix added a subscriber: cfe-commits.
jix set the repository for this revision to rL LLVM.
Herald added a subscriber: aemerson.

Parameter default values are expected to be attached to all redeclarations of a template. During serialization they are serialized only for the first redeclaration (probably to save space, see OwnsDefaultArg in ASTDeclWriter::VisitNonTypeTemplateParmDecl in ASTWriterDecl.cpp).

During deserialization the default arguments are recovered for all redeclartions by static void inheritDefaultTemplateArguments(... in ASTReaderDecl.cpp. This function includes the following optimization: As the parameters that have default values have to be at the end of the parameter list, it inherits them from back to front, stopping at the first parameter without a default. This works fine as long as there are no parameter packs, which may follow parameters with defaults.

The fix in this patch simply checks for parameter packs and skips them, continuing the default value inheritance for the preceding parameters.

Repository:
  rL LLVM

http://reviews.llvm.org/D16148

Files:
  lib/Serialization/ASTReaderDecl.cpp
  test/PCH/cxx-variadic-templates-with-default-params.cpp
  test/PCH/cxx-variadic-templates-with-default-params.h

Index: test/PCH/cxx-variadic-templates-with-default-params.h
===================================================================
--- test/PCH/cxx-variadic-templates-with-default-params.h
+++ test/PCH/cxx-variadic-templates-with-default-params.h
@@ -0,0 +1,8 @@
+// PR25271: Ensure that variadic template parameter defaults PCH roundtrip
+template<unsigned T=123, unsigned... U>
+class dummy;
+
+template<unsigned T, unsigned... U>
+class dummy {
+    int field[T];
+};
Index: test/PCH/cxx-variadic-templates-with-default-params.cpp
===================================================================
--- test/PCH/cxx-variadic-templates-with-default-params.cpp
+++ test/PCH/cxx-variadic-templates-with-default-params.cpp
@@ -0,0 +1,12 @@
+// Test this without pch.
+// RUN: %clang_cc1 -std=c++11 -include %S/cxx-variadic-templates-with-default-params.h -fsyntax-only -verify %s
+
+// Test with pch.
+// RUN: %clang_cc1 -std=c++11 -x c++-header -emit-pch -o %t %S/cxx-variadic-templates-with-default-params.h
+// RUN: %clang_cc1 -std=c++11 -include-pch %t -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+void f() {
+    dummy<> x;
+    (void)x;
+}
Index: lib/Serialization/ASTReaderDecl.cpp
===================================================================
--- lib/Serialization/ASTReaderDecl.cpp
+++ lib/Serialization/ASTReaderDecl.cpp
@@ -3000,6 +3000,8 @@
 
   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)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16148.44772.patch
Type: text/x-patch
Size: 1663 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160113/7589a529/attachment.bin>


More information about the cfe-commits mailing list