Skip to content

Commit b3a85c8

Browse files
committed
[Clang] Do not try to transform invalid bindings
In the presence of an invalid structured binding decomposition, some binding packs may be invalid and trying to transform them would produce a recovery expression that does not contains a pack, leading to assertions in places where we would expect a pack at that stage. Fixes #125165
1 parent 0caba6c commit b3a85c8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2481,7 +2481,7 @@ TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) {
24812481

24822482
if (BindingDecl *BD = dyn_cast<BindingDecl>(D); BD && BD->isParameterPack()) {
24832483
BD = cast_or_null<BindingDecl>(TransformDecl(BD->getLocation(), BD));
2484-
if (!BD)
2484+
if (!BD || BD->isInvalidDecl())
24852485
return ExprError();
24862486
if (auto *RP =
24872487
dyn_cast_if_present<ResolvedUnexpandedPackExpr>(BD->getBinding()))

clang/test/SemaCXX/cxx2c-binding-pack.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,19 @@ void other_main() {
188188
static_assert(f<int>() == 2);
189189
}
190190
} // namespace
191+
192+
193+
namespace GH125165 {
194+
195+
template <typename = void>
196+
auto f(auto t) {
197+
const auto& [...pack] = t;
198+
// expected-error@-1 {{cannot decompose non-class, non-array type 'char const'}}
199+
(pack, ...);
200+
};
201+
202+
void g() {
203+
f('x'); // expected-note {{in instantiation}}
204+
}
205+
206+
}

0 commit comments

Comments
 (0)