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
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: aa09911aeffb372899ef9fe6e87717bd81cceeb6
diff --git a/include/tuple b/include/tuple
index 15cbf26..f7e7ee1 100644
--- a/include/tuple
+++ b/include/tuple
@@ -1120,6 +1120,7 @@
bool
operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
{
+ static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
}
@@ -1163,6 +1164,7 @@
bool
operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
{
+ static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
return __tuple_less<sizeof...(_Tp)>()(__x, __y);
}