[clang] b8a1b69 - [clang] fix missing initialization of original number of expansions
Matheus Izvekov via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 15 08:40:09 PDT 2022
Author: Matheus Izvekov
Date: 2022-08-15T17:39:38+02:00
New Revision: b8a1b698afb2fc84819c7596090aabf4d826b436
URL: https://github.com/llvm/llvm-project/commit/b8a1b698afb2fc84819c7596090aabf4d826b436
DIFF: https://github.com/llvm/llvm-project/commit/b8a1b698afb2fc84819c7596090aabf4d826b436.diff
LOG: [clang] fix missing initialization of original number of expansions
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>
Differential Revision: https://reviews.llvm.org/D131802
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/TreeTransform.h
clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a635b734c47aa..ded0b39c27ea5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -71,6 +71,9 @@ Bug Fixes
- Fix `#57008 <https://github.com/llvm/llvm-project/issues/57008>`_ - Builtin
C++ language extension type traits instantiated by a template with unexpected
number of arguments cause an assertion fault.
+- Fix multi-level pack expansion of undeclared function parameters.
+ This fixes `Issue 56094 <https://github.com/llvm/llvm-project/issues/56094>`_.
+
Improvements to Clang's diagnostics
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 07e71a2be4f2c..dd684d42665b2 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -5792,6 +5792,7 @@ bool TreeTransform<Derived>::TransformFunctionTypeParams(
= 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);
diff --git a/clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp b/clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
index 206e9f73e9f05..6c4c260cdf8f0 100644
--- a/clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
+++ b/clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
@@ -469,3 +469,25 @@ int fn() {
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
diff erent 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
diff erent 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
More information about the cfe-commits
mailing list