Skip to content

Commit 80ccf01

Browse files
authored
[Clang] Do not try to transform invalid bindings (#125658)
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 826af17 commit 80ccf01

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

clang/lib/Sema/TreeTransform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12716,7 +12716,7 @@ TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
1271612716
ValueDecl *ND
1271712717
= cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
1271812718
E->getDecl()));
12719-
if (!ND)
12719+
if (!ND || ND->isInvalidDecl())
1272012720
return ExprError();
1272112721

1272212722
NamedDecl *Found = ND;

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,18 @@ auto X = [] <typename = void> () {
218218
static_assert(sizeof...(pack3) == 5);
219219
};
220220
} // namespace
221+
222+
namespace GH125165 {
223+
224+
template <typename = void>
225+
auto f(auto t) {
226+
const auto& [...pack] = t;
227+
// expected-error@-1 {{cannot decompose non-class, non-array type 'char const'}}
228+
(pack, ...);
229+
};
230+
231+
void g() {
232+
f('x'); // expected-note {{in instantiation}}
233+
}
234+
235+
}

0 commit comments

Comments
 (0)