From f1e473bad91ade08503be6549c2cb4f229835327 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 16 Sep 2014 20:38:11 +0000 Subject: Create a 'comma_iterator' class that overloads operator, and asserts when it's called. Add tests to mismatch to make sure it can't be blindsided by such an evil iterator. More tests for other algorithms forthcoming. Thanks to STL for pointing this out at CppCon and Yakov Galka for opening LWG issue #2133 llvm-svn: 217902 --- .../test/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp | 8 ++++++++ .../algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp | 8 ++++++++ 2 files changed, 16 insertions(+) (limited to 'libcxx/test/algorithms') diff --git a/libcxx/test/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp b/libcxx/test/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp index fe678541382..78f795afae4 100644 --- a/libcxx/test/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp +++ b/libcxx/test/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp @@ -36,6 +36,14 @@ int main() input_iterator(ia+3), input_iterator(ib+3)))); + assert(std::mismatch(comma_iterator(ia), + comma_iterator(ia + sa), + comma_iterator(ib)) == + (std::pair, + comma_iterator >( + comma_iterator(ia+3), + comma_iterator(ib+3)))); + #ifdef HAS_FOUR_ITERATOR_VERSION assert(std::mismatch(input_iterator(ia), input_iterator(ia + sa), diff --git a/libcxx/test/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp b/libcxx/test/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp index 202a1b7bcb6..aeb74104bb4 100644 --- a/libcxx/test/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp +++ b/libcxx/test/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp @@ -39,6 +39,14 @@ int main() input_iterator >( input_iterator(ia+3), input_iterator(ib+3)))); + assert(std::mismatch(comma_iterator(ia), + comma_iterator(ia + sa), + comma_iterator(ib), + std::equal_to()) == + (std::pair, + comma_iterator >( + comma_iterator(ia+3), + comma_iterator(ib+3)))); #ifdef HAS_FOUR_ITERATOR_VERSION assert(std::mismatch(input_iterator(ia), input_iterator(ia + sa), -- cgit v1.2.3