diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2019-02-07 19:03:48 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2019-02-07 19:03:48 +0000 |
commit | b72412d276b6d43ee2f84f94417946e8abe0447a (patch) | |
tree | f79d8d2a0f28cc9ea9e66d4a7dec4be8eb50de76 | |
parent | 0c922504853a5ef4c8ded9cedefd86ae1875fcdb (diff) | |
download | libcxx-b72412d276b6d43ee2f84f94417946e8abe0447a.tar.gz |
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
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@353450 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/tuple | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/include/tuple b/include/tuple index 15cbf2689..f7e7ee194 100644 --- a/include/tuple +++ b/include/tuple @@ -1120,6 +1120,7 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 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_CONSTEXPR_AFTER_CXX11 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); } |