Skip to content

Commit aa09911

Browse files
committed
Add static_asserts to tuple's comparison operators to enforce the requirement that the tuples be the same size. See PR39183 for an example where we give unexpected results for this bad input case. With this change, we will reject it at compile-time
llvm-svn: 353450
1 parent d6212f9 commit aa09911

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

libcxx/include/tuple

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
11201120
bool
11211121
operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
11221122
{
1123+
static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
11231124
return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
11241125
}
11251126

@@ -1163,6 +1164,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
11631164
bool
11641165
operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
11651166
{
1167+
static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
11661168
return __tuple_less<sizeof...(_Tp)>()(__x, __y);
11671169
}
11681170

0 commit comments

Comments
 (0)