From e02ed1c255d717827268fd0789148a06df5d0970 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Thu, 13 Apr 2017 02:54:13 +0000 Subject: Diagnose when reverse_iterator is used on path::iterator. path::iterator isn't a strictly conforming iterator. Specifically it stashes the current element inside the iterator. This leads to UB when used with reverse_iterator since it requires the element to outlive the lifetime of the iterator. This patch adds a static_assert inside reverse_iterator to disallow "stashing iterator types", and it tags path::iterator as such a type. Additionally this patch removes all uses of reverse_iterator within the tests. llvm-svn: 300164 --- .../path.member/path.decompose/path.decompose.pass.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'libcxx/test/std/experimental/filesystem/class.path/path.member/path.decompose/path.decompose.pass.cpp') diff --git a/libcxx/test/std/experimental/filesystem/class.path/path.member/path.decompose/path.decompose.pass.cpp b/libcxx/test/std/experimental/filesystem/class.path/path.member/path.decompose/path.decompose.pass.cpp index 4c83481aaf2..078e006663e 100644 --- a/libcxx/test/std/experimental/filesystem/class.path/path.member/path.decompose/path.decompose.pass.cpp +++ b/libcxx/test/std/experimental/filesystem/class.path/path.member/path.decompose/path.decompose.pass.cpp @@ -54,12 +54,6 @@ #include "count_new.hpp" #include "filesystem_test_helper.hpp" -template -std::reverse_iterator mkRev(It it) { - return std::reverse_iterator(it); -} - - namespace fs = std::experimental::filesystem; struct PathDecomposeTestcase { @@ -147,7 +141,11 @@ void decompPathTest() assert(checkCollectionsEqual(p.begin(), p.end(), TC.elements.begin(), TC.elements.end())); // check backwards - assert(checkCollectionsEqual(mkRev(p.end()), mkRev(p.begin()), + + std::vector Parts; + for (auto it = p.end(); it != p.begin(); ) + Parts.push_back(*--it); + assert(checkCollectionsEqual(Parts.begin(), Parts.end(), TC.elements.rbegin(), TC.elements.rend())); } } -- cgit v1.2.3