Commit 4fe5c8c7 by Jonathan Wakely Committed by Jonathan Wakely

Add noexcept to filesystem::path query functions

In the standard these member functions are specified in terms of the
potentially-throwing path decompositions functions, but we implement
them without constructing any new paths or doing anything else that can
throw.

	PR libstdc++/71044
	* include/bits/fs_path.h (path::has_root_name)
	(path::has_root_directory, path::has_root_path)
	(path::has_relative_path, path::has_parent_path)
	(path::has_filename, path::has_stem, path::has_extension)
	(path::is_absolute, path::is_relative, path::_M_find_extension): Add
	noexcept.
	* src/c++17/fs_path.cc (path::has_root_name)
	(path::has_root_directory, path::has_root_path)
	(path::has_relative_path, path::has_parent_path)
	(path::has_filename, path::_M_find_extension): Add noexcept.

From-SVN: r268713
parent 5b0bf815
2019-02-09 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/71044
* include/bits/fs_path.h (path::has_root_name)
(path::has_root_directory, path::has_root_path)
(path::has_relative_path, path::has_parent_path)
(path::has_filename, path::has_stem, path::has_extension)
(path::is_absolute, path::is_relative, path::_M_find_extension): Add
noexcept.
* src/c++17/fs_path.cc (path::has_root_name)
(path::has_root_directory, path::has_root_path)
(path::has_relative_path, path::has_parent_path)
(path::has_filename, path::_M_find_extension): Add noexcept.
2019-02-06 Jonathan Wakely <jwakely@redhat.com> 2019-02-06 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/89102 (partial) PR libstdc++/89102 (partial)
......
...@@ -359,16 +359,16 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -359,16 +359,16 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
// query // query
[[nodiscard]] bool empty() const noexcept { return _M_pathname.empty(); } [[nodiscard]] bool empty() const noexcept { return _M_pathname.empty(); }
bool has_root_name() const; bool has_root_name() const noexcept;
bool has_root_directory() const; bool has_root_directory() const noexcept;
bool has_root_path() const; bool has_root_path() const noexcept;
bool has_relative_path() const; bool has_relative_path() const noexcept;
bool has_parent_path() const; bool has_parent_path() const noexcept;
bool has_filename() const; bool has_filename() const noexcept;
bool has_stem() const; bool has_stem() const noexcept;
bool has_extension() const; bool has_extension() const noexcept;
bool is_absolute() const; bool is_absolute() const noexcept;
bool is_relative() const { return !is_absolute(); } bool is_relative() const noexcept { return !is_absolute(); }
// generation // generation
path lexically_normal() const; path lexically_normal() const;
...@@ -433,7 +433,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -433,7 +433,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
void _M_append(basic_string_view<value_type>); void _M_append(basic_string_view<value_type>);
void _M_concat(basic_string_view<value_type>); void _M_concat(basic_string_view<value_type>);
pair<const string_type*, size_t> _M_find_extension() const; pair<const string_type*, size_t> _M_find_extension() const noexcept;
template<typename _CharT> template<typename _CharT>
struct _Cvt; struct _Cvt;
...@@ -1102,21 +1102,21 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -1102,21 +1102,21 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
} }
inline bool inline bool
path::has_stem() const path::has_stem() const noexcept
{ {
auto ext = _M_find_extension(); auto ext = _M_find_extension();
return ext.first && ext.second != 0; return ext.first && ext.second != 0;
} }
inline bool inline bool
path::has_extension() const path::has_extension() const noexcept
{ {
auto ext = _M_find_extension(); auto ext = _M_find_extension();
return ext.first && ext.second != string_type::npos; return ext.first && ext.second != string_type::npos;
} }
inline bool inline bool
path::is_absolute() const path::is_absolute() const noexcept
{ {
#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
return has_root_name() && has_root_directory(); return has_root_name() && has_root_directory();
......
...@@ -1530,7 +1530,7 @@ path::parent_path() const ...@@ -1530,7 +1530,7 @@ path::parent_path() const
} }
bool bool
path::has_root_name() const path::has_root_name() const noexcept
{ {
if (_M_type() == _Type::_Root_name) if (_M_type() == _Type::_Root_name)
return true; return true;
...@@ -1540,7 +1540,7 @@ path::has_root_name() const ...@@ -1540,7 +1540,7 @@ path::has_root_name() const
} }
bool bool
path::has_root_directory() const path::has_root_directory() const noexcept
{ {
if (_M_type() == _Type::_Root_dir) if (_M_type() == _Type::_Root_dir)
return true; return true;
...@@ -1556,7 +1556,7 @@ path::has_root_directory() const ...@@ -1556,7 +1556,7 @@ path::has_root_directory() const
} }
bool bool
path::has_root_path() const path::has_root_path() const noexcept
{ {
if (_M_type() == _Type::_Root_name || _M_type() == _Type::_Root_dir) if (_M_type() == _Type::_Root_name || _M_type() == _Type::_Root_dir)
return true; return true;
...@@ -1570,7 +1570,7 @@ path::has_root_path() const ...@@ -1570,7 +1570,7 @@ path::has_root_path() const
} }
bool bool
path::has_relative_path() const path::has_relative_path() const noexcept
{ {
if (_M_type() == _Type::_Filename && !_M_pathname.empty()) if (_M_type() == _Type::_Filename && !_M_pathname.empty())
return true; return true;
...@@ -1589,7 +1589,7 @@ path::has_relative_path() const ...@@ -1589,7 +1589,7 @@ path::has_relative_path() const
bool bool
path::has_parent_path() const path::has_parent_path() const noexcept
{ {
if (!has_relative_path()) if (!has_relative_path())
return !empty(); return !empty();
...@@ -1597,7 +1597,7 @@ path::has_parent_path() const ...@@ -1597,7 +1597,7 @@ path::has_parent_path() const
} }
bool bool
path::has_filename() const path::has_filename() const noexcept
{ {
if (empty()) if (empty())
return false; return false;
...@@ -1783,7 +1783,7 @@ path::lexically_proximate(const path& base) const ...@@ -1783,7 +1783,7 @@ path::lexically_proximate(const path& base) const
} }
std::pair<const path::string_type*, std::size_t> std::pair<const path::string_type*, std::size_t>
path::_M_find_extension() const path::_M_find_extension() const noexcept
{ {
const string_type* s = nullptr; const string_type* s = nullptr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment