Skip to content

Commit 5fcc0e2

Browse files
committed
[clang][Sema] Reject negative tuple sizes
Fixes #159563
1 parent 29620d9 commit 5fcc0e2

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ static IsTupleLike isTupleLike(Sema &S, SourceLocation Loc, QualType T,
12191219
return IsTupleLike::Error;
12201220

12211221
E = S.VerifyIntegerConstantExpression(E.get(), &Size, Diagnoser);
1222-
if (E.isInvalid())
1222+
if (E.isInvalid() || Size.isNegative())
12231223
return IsTupleLike::Error;
12241224

12251225
return IsTupleLike::TupleLike;

clang/test/SemaCXX/builtin-structured-binding-size.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,12 @@ static_assert(__is_same_as(tag_of_t<S1>, int));
229229
static_assert(__is_same_as(tag_of_t<int>, int)); // error
230230
// expected-error@-1 {{constraints not satisfied for alias template 'tag_of_t' [with T = int]}}
231231
// expected-note@#tag-of-constr {{because substituted constraint expression is ill-formed: type 'int' cannot be decomposed}}
232+
233+
struct Neg {
234+
int a;
235+
};
236+
template <> struct std::tuple_size<Neg> {
237+
static constexpr int value = -1;
238+
};
239+
240+
int e = __builtin_structured_binding_size(Neg); // expected-error {{type 'Neg' cannot be decomposed}}

0 commit comments

Comments
 (0)