diff options
author | Eric Fiselier <eric@efcs.ca> | 2018-07-25 03:31:48 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2018-07-25 03:31:48 +0000 |
commit | 52ec6a206f15ee84308c56d5bd7e906e9235f510 (patch) | |
tree | 290d757ba6704882955a2c3a161979f76550e55e /libcxx | |
parent | 179757ef054baabf09053b189ee4f9ea4e0e3c7f (diff) | |
download | bcm5719-llvm-52ec6a206f15ee84308c56d5bd7e906e9235f510.tar.gz bcm5719-llvm-52ec6a206f15ee84308c56d5bd7e906e9235f510.zip |
Ensure path::iterator and PathParser share the same enumeration values.
To avoid exposing implementation details, path::iterator and PathParser
both implicitly used the same set of values to represent the state,
but they were defined twice. This could have lead to a mismatch
occuring.
This patch moves all of the parser state values into the filesystem
header and changes PathParser to use those value to avoid this.
llvm-svn: 337883
Diffstat (limited to 'libcxx')
-rw-r--r-- | libcxx/include/experimental/filesystem | 27 | ||||
-rw-r--r-- | libcxx/src/experimental/filesystem/operations.cpp | 21 |
2 files changed, 28 insertions, 20 deletions
diff --git a/libcxx/include/experimental/filesystem b/libcxx/include/experimental/filesystem index 9699699c718..1f6d1ab4d96 100644 --- a/libcxx/include/experimental/filesystem +++ b/libcxx/include/experimental/filesystem @@ -1037,7 +1037,7 @@ public: _LIBCPP_INLINE_VISIBILITY path extension() const { return string_type(__extension()); } // query - _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT { return __pn_.empty(); } _LIBCPP_INLINE_VISIBILITY bool has_root_name() const { return !__root_name().empty(); } @@ -1170,6 +1170,17 @@ u8path(_InputIt __f, _InputIt __l) { class _LIBCPP_TYPE_VIS path::iterator { public: + enum _ParserState : unsigned char { + _Singular, + _BeforeBegin, + _InRootName, + _InRootDir, + _InFilenames, + _InTrailingSep, + _AtEnd + }; + +public: typedef bidirectional_iterator_tag iterator_category; typedef path value_type; @@ -1178,10 +1189,11 @@ public: typedef const path& reference; typedef void __stashing_iterator_tag; // See reverse_iterator and __is_stashing_iterator + public: _LIBCPP_INLINE_VISIBILITY iterator() : __stashed_elem_(), __path_ptr_(nullptr), - __entry_(), __state_(__singular) {} + __entry_(), __state_(_Singular) {} iterator(const iterator&) = default; ~iterator() = default; @@ -1200,9 +1212,9 @@ public: _LIBCPP_INLINE_VISIBILITY iterator& operator++() { - _LIBCPP_ASSERT(__state_ != __singular, + _LIBCPP_ASSERT(__state_ != _Singular, "attempting to increment a singular iterator"); - _LIBCPP_ASSERT(__state_ != __at_end, + _LIBCPP_ASSERT(__state_ != _AtEnd, "attempting to increment the end iterator"); return __increment(); } @@ -1216,7 +1228,7 @@ public: _LIBCPP_INLINE_VISIBILITY iterator& operator--() { - _LIBCPP_ASSERT(__state_ != __singular, + _LIBCPP_ASSERT(__state_ != _Singular, "attempting to decrement a singular iterator"); _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(), "attempting to decrement the begin iterator"); @@ -1233,9 +1245,6 @@ public: private: friend class path; - static constexpr unsigned char __singular = 0; - static constexpr unsigned char __at_end = 6; - inline _LIBCPP_INLINE_VISIBILITY friend bool operator==(const iterator&, const iterator&); @@ -1245,7 +1254,7 @@ private: path __stashed_elem_; const path* __path_ptr_; path::__string_view __entry_; - unsigned char __state_; + _ParserState __state_; }; inline _LIBCPP_INLINE_VISIBILITY diff --git a/libcxx/src/experimental/filesystem/operations.cpp b/libcxx/src/experimental/filesystem/operations.cpp index dd805193b98..089e34b203b 100644 --- a/libcxx/src/experimental/filesystem/operations.cpp +++ b/libcxx/src/experimental/filesystem/operations.cpp @@ -57,12 +57,12 @@ using PosPtr = path::value_type const*; struct PathParser { enum ParserState : unsigned char { // Zero is a special sentinel value used by default constructed iterators. - PS_BeforeBegin = 1, - PS_InRootName, - PS_InRootDir, - PS_InFilenames, - PS_InTrailingSep, - PS_AtEnd + PS_BeforeBegin = path::iterator::_BeforeBegin, + PS_InRootName = path::iterator::_InRootName, + PS_InRootDir = path::iterator::_InRootDir, + PS_InFilenames = path::iterator::_InFilenames, + PS_InTrailingSep = path::iterator::_InTrailingSep, + PS_AtEnd = path::iterator::_AtEnd }; const string_view_t Path; @@ -1548,7 +1548,7 @@ path::iterator path::begin() const auto PP = PathParser::CreateBegin(__pn_); iterator it; it.__path_ptr_ = this; - it.__state_ = PP.State; + it.__state_ = static_cast<path::iterator::_ParserState>(PP.State); it.__entry_ = PP.RawEntry; it.__stashed_elem_.__assign_view(*PP); return it; @@ -1557,16 +1557,15 @@ path::iterator path::begin() const path::iterator path::end() const { iterator it{}; - it.__state_ = PathParser::PS_AtEnd; + it.__state_ = path::iterator::_AtEnd; it.__path_ptr_ = this; return it; } path::iterator& path::iterator::__increment() { - static_assert(__at_end == PathParser::PS_AtEnd, ""); PathParser PP(__path_ptr_->native(), __entry_, __state_); ++PP; - __state_ = PP.State; + __state_ = static_cast<_ParserState>(PP.State); __entry_ = PP.RawEntry; __stashed_elem_.__assign_view(*PP); return *this; @@ -1575,7 +1574,7 @@ path::iterator& path::iterator::__increment() { path::iterator& path::iterator::__decrement() { PathParser PP(__path_ptr_->native(), __entry_, __state_); --PP; - __state_ = PP.State; + __state_ = static_cast<_ParserState>(PP.State); __entry_ = PP.RawEntry; __stashed_elem_.__assign_view(*PP); return *this; |