[PATCH] D131802: WIP: [clang] fix missing initialization of original number of expansions

Matheus Izvekov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 12 12:59:29 PDT 2022


mizvekov created this revision.
Herald added projects: clang, All.
Herald added a subscriber: cfe-commits.
mizvekov requested review of this revision.

When expanding undeclared function parameters, we should initialize
the original number of expansions, if known, before trying to expand
them, otherwise a length mismatch with an outer pack might not be
diagnosed.

Fixes PR56094.

Signed-off-by: Matheus Izvekov <mizvekov at gmail.com>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131802

Files:
  clang/lib/Sema/TreeTransform.h
  clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp


Index: clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
===================================================================
--- clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
+++ clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
@@ -469,3 +469,25 @@
   bar(b);
 }
 }
+
+namespace pr56094 {
+template <typename... T> struct D {
+  template <typename... U> using B = int(int (*...p)(T, U));
+  // expected-error at -1 {{pack expansion contains parameter pack 'U' that has a different length (1 vs. 2) from outer parameter packs}}
+  template <typename U1, typename U2> D(B<U1, U2> *);
+  // expected-note at -1 {{in instantiation of template type alias 'B' requested here}}
+};
+using t1 = D<float>::B<int>;
+// expected-note at -1 {{in instantiation of template class 'pr56094::D<float>' requested here}}
+
+template <bool...> struct F {};
+template <class...> struct G {};
+template <bool... I> struct E {
+  template <bool... U> using B = G<F<I, U>...>;
+  // expected-error at -1 {{pack expansion contains parameter pack 'U' that has a different length (1 vs. 2) from outer parameter packs}}
+  template <bool U1, bool U2> E(B<U1, U2> *);
+  // expected-note at -1 {{in instantiation of template type alias 'B' requested here}}
+};
+using t2 = E<true>::B<false>;
+// expected-note at -1 {{in instantiation of template class 'pr56094::E<true>' requested here}}
+} // namespace pr56094
Index: clang/lib/Sema/TreeTransform.h
===================================================================
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -5792,6 +5792,7 @@
                                        = dyn_cast<PackExpansionType>(OldType)) {
       // We have a function parameter pack that may need to be expanded.
       QualType Pattern = Expansion->getPattern();
+      NumExpansions = Expansion->getNumExpansions();
       SmallVector<UnexpandedParameterPack, 2> Unexpanded;
       getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131802.452281.patch
Type: text/x-patch
Size: 1969 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220812/4229f692/attachment.bin>


More information about the cfe-commits mailing list