[libcxx-commits] [libcxx] r353450 - 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

Marshall Clow via libcxx-commits libcxx-commits at lists.llvm.org
Thu Feb 7 11:03:48 PST 2019


Author: marshall
Date: Thu Feb  7 11:03:48 2019
New Revision: 353450

URL: http://llvm.org/viewvc/llvm-project?rev=353450&view=rev
Log:
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

Modified:
    libcxx/trunk/include/tuple

Modified: libcxx/trunk/include/tuple
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/tuple?rev=353450&r1=353449&r2=353450&view=diff
==============================================================================
--- libcxx/trunk/include/tuple (original)
+++ libcxx/trunk/include/tuple Thu Feb  7 11:03:48 2019
@@ -1120,6 +1120,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP
 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 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP
 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);
 }
 




More information about the libcxx-commits mailing list