Skip to content

Commit 15ccaa0

Browse files
committed
[Clang] Correctly recognize unexpanded packs in lambda template params
Fixes #48937 Fixes #49099
1 parent c026135 commit 15ccaa0

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ ABI Changes in This Version
103103
ifuncs. Its purpose was to preserve backwards compatibility when the ".ifunc"
104104
suffix got removed from the name mangling. The alias interacts badly with
105105
GlobalOpt (see the issue #96197).
106-
106+
107107
- Fixed Microsoft name mangling for auto non-type template arguments of pointer
108108
type for MSVC 1920+. This change resolves incompatibilities with code compiled
109109
by MSVC 1920+ but will introduce incompatibilities with code compiled by
@@ -1024,6 +1024,8 @@ Bug Fixes to C++ Support
10241024
- Fixed a bug where references to lambda capture inside a ``noexcept`` specifier were not correctly
10251025
instantiated. (#GH95735).
10261026
- Fixed a CTAD substitution bug involving type aliases that reference outer template parameters. (#GH94614).
1027+
- Clang now correctly handles unexpanded packs in the template parameter list of a generic lambda expression
1028+
(#GH48937)
10271029

10281030
Bug Fixes to AST Handling
10291031
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaLambda.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,8 @@ void Sema::ActOnLambdaClosureParameters(
13801380
AddTemplateParametersToLambdaCallOperator(LSI->CallOperator, LSI->Lambda,
13811381
TemplateParams);
13821382
LSI->Lambda->setLambdaIsGeneric(true);
1383+
LSI->ContainsUnexpandedParameterPack |=
1384+
TemplateParams->containsUnexpandedParameterPack();
13831385
}
13841386
LSI->AfterParameterList = true;
13851387
}

clang/test/SemaCXX/lambda-pack-expansion.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,24 @@ void foo() {
2020
take_by_ref(x);
2121
}
2222
}
23+
24+
namespace GH48937 {
25+
26+
template <typename... Ts>
27+
consteval int f(Ts... ts) {
28+
return ([]<Ts a = 42>(){ return a;}, ...)();
29+
}
30+
31+
static_assert(f(0, 42) == 42);
32+
33+
template <typename Ts>
34+
int g(Ts ts) {
35+
return ([]<Ts a = 42>(){ return a;}, ...)(); // expected-error {{pack expansion does not contain any unexpanded parameter packs}}
36+
}
37+
38+
template <typename... Ts>
39+
int h(Ts... ts) {
40+
return ([]<Ts a = 42>(){ return a;})(); // expected-error {{expression contains unexpanded parameter pack 'Ts'}}
41+
}
42+
43+
}

0 commit comments

Comments
 (0)