[libcxx] r349884 - Implement LWG 3065: Make path operators friends.
Eric Fiselier
eric at efcs.ca
Thu Dec 20 20:09:02 PST 2018
Author: ericwf
Date: Thu Dec 20 20:09:01 2018
New Revision: 349884
URL: http://llvm.org/viewvc/llvm-project?rev=349884&view=rev
Log:
Implement LWG 3065: Make path operators friends.
This prevents things like:
using namespace std::filesystem;
auto x = L"a/b" == std::string("a/b");
Added:
libcxx/trunk/test/std/input.output/filesystems/class.path/path.nonmember/append_op.fail.cpp
- copied, changed from r349883, libcxx/trunk/test/std/input.output/filesystems/class.path/path.nonmember/append_op.pass.cpp
libcxx/trunk/test/std/input.output/filesystems/class.path/path.nonmember/comparison_ops.fail.cpp
Modified:
libcxx/trunk/include/filesystem
libcxx/trunk/test/std/input.output/filesystems/class.path/path.nonmember/append_op.pass.cpp
libcxx/trunk/www/cxx2a_status.html
Modified: libcxx/trunk/include/filesystem
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/filesystem?rev=349884&r1=349883&r2=349884&view=diff
==============================================================================
--- libcxx/trunk/include/filesystem (original)
+++ libcxx/trunk/include/filesystem Thu Dec 20 20:09:01 2018
@@ -1151,6 +1151,31 @@ public:
return __is;
}
+ friend _LIBCPP_INLINE_VISIBILITY bool operator==(const path& __lhs, const path& __rhs) noexcept {
+ return __lhs.compare(__rhs) == 0;
+ }
+ friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const path& __lhs, const path& __rhs) noexcept {
+ return __lhs.compare(__rhs) != 0;
+ }
+ friend _LIBCPP_INLINE_VISIBILITY bool operator<(const path& __lhs, const path& __rhs) noexcept {
+ return __lhs.compare(__rhs) < 0;
+ }
+ friend _LIBCPP_INLINE_VISIBILITY bool operator<=(const path& __lhs, const path& __rhs) noexcept {
+ return __lhs.compare(__rhs) <= 0;
+ }
+ friend _LIBCPP_INLINE_VISIBILITY bool operator>(const path& __lhs, const path& __rhs) noexcept {
+ return __lhs.compare(__rhs) > 0;
+ }
+ friend _LIBCPP_INLINE_VISIBILITY bool operator>=(const path& __lhs, const path& __rhs) noexcept {
+ return __lhs.compare(__rhs) >= 0;
+ }
+
+ friend _LIBCPP_INLINE_VISIBILITY path operator/(const path& __lhs,
+ const path& __rhs) {
+ path __result(__lhs);
+ __result /= __rhs;
+ return __result;
+ }
private:
inline _LIBCPP_INLINE_VISIBILITY path&
__assign_view(__string_view const& __s) noexcept {
@@ -1167,43 +1192,6 @@ inline _LIBCPP_INLINE_VISIBILITY void sw
_LIBCPP_FUNC_VIS
size_t hash_value(const path& __p) noexcept;
-inline _LIBCPP_INLINE_VISIBILITY bool operator==(const path& __lhs,
- const path& __rhs) noexcept {
- return __lhs.compare(__rhs) == 0;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const path& __lhs,
- const path& __rhs) noexcept {
- return __lhs.compare(__rhs) != 0;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool operator<(const path& __lhs,
- const path& __rhs) noexcept {
- return __lhs.compare(__rhs) < 0;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool operator<=(const path& __lhs,
- const path& __rhs) noexcept {
- return __lhs.compare(__rhs) <= 0;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool operator>(const path& __lhs,
- const path& __rhs) noexcept {
- return __lhs.compare(__rhs) > 0;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY bool operator>=(const path& __lhs,
- const path& __rhs) noexcept {
- return __lhs.compare(__rhs) >= 0;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY path operator/(const path& __lhs,
- const path& __rhs) {
- path __result(__lhs);
- __result /= __rhs;
- return __result;
-}
-
template <class _Source>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_pathable<_Source>::value, path>::type
Copied: libcxx/trunk/test/std/input.output/filesystems/class.path/path.nonmember/append_op.fail.cpp (from r349883, libcxx/trunk/test/std/input.output/filesystems/class.path/path.nonmember/append_op.pass.cpp)
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/input.output/filesystems/class.path/path.nonmember/append_op.fail.cpp?p2=libcxx/trunk/test/std/input.output/filesystems/class.path/path.nonmember/append_op.fail.cpp&p1=libcxx/trunk/test/std/input.output/filesystems/class.path/path.nonmember/append_op.pass.cpp&r1=349883&r2=349884&rev=349884&view=diff
==============================================================================
--- libcxx/trunk/test/std/input.output/filesystems/class.path/path.nonmember/append_op.pass.cpp (original)
+++ libcxx/trunk/test/std/input.output/filesystems/class.path/path.nonmember/append_op.fail.cpp Thu Dec 20 20:09:01 2018
@@ -11,22 +11,17 @@
// <filesystem>
-// path operator/(path const&, path const&);
-
#include "filesystem_include.hpp"
-#include <type_traits>
-#include <cassert>
-
-#include "test_macros.h"
-#include "filesystem_test_helper.hpp"
+using namespace fs;
-// This is mainly tested via the member append functions.
-int main()
-{
- using namespace fs;
- path p1("abc");
- path p2("def");
- path p3 = p1 / p2;
- assert(p3 == "abc/def");
-}
+struct ConvToPath {
+ operator fs::path() const {
+ return "";
+ }
+};
+
+int main() {
+ ConvToPath LHS, RHS;
+ (void)(LHS / RHS); // expected-error {{invalid operands to binary expression}}
+}
\ No newline at end of file
Modified: libcxx/trunk/test/std/input.output/filesystems/class.path/path.nonmember/append_op.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/input.output/filesystems/class.path/path.nonmember/append_op.pass.cpp?rev=349884&r1=349883&r2=349884&view=diff
==============================================================================
--- libcxx/trunk/test/std/input.output/filesystems/class.path/path.nonmember/append_op.pass.cpp (original)
+++ libcxx/trunk/test/std/input.output/filesystems/class.path/path.nonmember/append_op.pass.cpp Thu Dec 20 20:09:01 2018
@@ -20,7 +20,6 @@
#include "test_macros.h"
#include "filesystem_test_helper.hpp"
-
// This is mainly tested via the member append functions.
int main()
{
@@ -29,4 +28,7 @@ int main()
path p2("def");
path p3 = p1 / p2;
assert(p3 == "abc/def");
+
+ path p4 = p1 / "def";
+ assert(p4 == "abc/def");
}
Added: libcxx/trunk/test/std/input.output/filesystems/class.path/path.nonmember/comparison_ops.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/input.output/filesystems/class.path/path.nonmember/comparison_ops.fail.cpp?rev=349884&view=auto
==============================================================================
--- libcxx/trunk/test/std/input.output/filesystems/class.path/path.nonmember/comparison_ops.fail.cpp (added)
+++ libcxx/trunk/test/std/input.output/filesystems/class.path/path.nonmember/comparison_ops.fail.cpp Thu Dec 20 20:09:01 2018
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++98, c++03
+
+// <filesystem>
+
+
+#include "filesystem_include.hpp"
+
+using namespace fs;
+
+struct ConvToPath {
+ operator fs::path() const {
+ return "";
+ }
+};
+
+int main() {
+ ConvToPath LHS, RHS;
+ (void)(LHS == RHS); // expected-error {{invalid operands to binary expression}}
+ (void)(LHS != RHS); // expected-error {{invalid operands to binary expression}}
+ (void)(LHS < RHS); // expected-error {{invalid operands to binary expression}}
+ (void)(LHS <= RHS); // expected-error {{invalid operands to binary expression}}
+ (void)(LHS > RHS); // expected-error {{invalid operands to binary expression}}
+ (void)(LHS >= RHS); // expected-error {{invalid operands to binary expression}}
+}
\ No newline at end of file
Modified: libcxx/trunk/www/cxx2a_status.html
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx2a_status.html?rev=349884&r1=349883&r2=349884&view=diff
==============================================================================
--- libcxx/trunk/www/cxx2a_status.html (original)
+++ libcxx/trunk/www/cxx2a_status.html Thu Dec 20 20:09:01 2018
@@ -270,7 +270,7 @@
<tr><td><a href="https://wg21.link/LWG3037">3037</a></td><td><tt>polymorphic_allocator</tt> and incomplete types</td><td>San Diego</td><td></td></tr>
<tr><td><a href="https://wg21.link/LWG3038">3038</a></td><td><tt>polymorphic_allocator::allocate</tt> should not allow integer overflow to create vulnerabilities</td><td>San Diego</td><td></td></tr>
<tr><td><a href="https://wg21.link/LWG3054">3054</a></td><td><tt>uninitialized_copy</tt> appears to not be able to meet its exception-safety guarantee</td><td>San Diego</td><td></td></tr>
- <tr><td><a href="https://wg21.link/LWG3065">3065</a></td><td>LWG 2989 missed that all <tt>path</tt>'s other operators should be hidden friends as well</td><td>San Diego</td><td></td></tr>
+ <tr><td><a href="https://wg21.link/LWG3065">3065</a></td><td>LWG 2989 missed that all <tt>path</tt>'s other operators should be hidden friends as well</td><td>San Diego</td><td>Complete</td></tr>
<tr><td><a href="https://wg21.link/LWG3096">3096</a></td><td><tt>path::lexically_relative</tt> is confused by trailing slashes</td><td>San Diego</td><td></td></tr>
<tr><td><a href="https://wg21.link/LWG3116">3116</a></td><td><tt><i>OUTERMOST_ALLOC_TRAITS</i></tt> needs <tt>remove_reference_t</tt></td><td>San Diego</td><td></td></tr>
<tr><td><a href="https://wg21.link/LWG3122">3122</a></td><td><tt>__cpp_lib_chrono_udls</tt> was accidentally dropped</td><td>San Diego</td><td><i>We've already made the update; but we don't support all the test macros. When we do, this will be closed</i></td></tr>
More information about the libcxx-commits
mailing list