[PATCH] Add __gnu_test::NullablePointer utility to testsuite

2019-05-14 Thread Jonathan Wakely

* testsuite/20_util/allocator_traits/members/allocate_hint_nonpod.cc:
Use operator-> to access raw pointer member.
* testsuite/23_containers/vector/59829.cc: Likewise.
* testsuite/23_containers/vector/bool/80893.cc: Likewise.
* testsuite/libstdc++-prettyprinters/cxx11.cc: Use NullablePointer.
* testsuite/util/testsuite_allocator.h (NullablePointer): New utility
for tests.
(PointerBase, PointerBase_void): Derive from NullablePointer and use
its constructors and equality operators. Change converting
constructors to use operator-> to access private member of the other
pointer type.
(PointerBase_void::operator->()): Add, for access to private member.
(operator-(PointerBase, PointerBase)): Change to hidden friend.
(operator==(PointerBase, PointerBase)): Remove.
(operator!=(PointerBase, PointerBase)): Remove.

There are probably more places in the testsuite that could use
NullablePointer as a minimally-conforming type that meets the
Cpp17NullablePointer requirements, instead of defining a new type each
time one is needed.

Tested powerpc64le-linux, committed to trunk.

commit d238e99b1eea20ba5bb52df6d4544fb4062fb075
Author: Jonathan Wakely 
Date:   Tue May 14 11:02:41 2019 +0100

Add __gnu_test::NullablePointer utility to testsuite

* 
testsuite/20_util/allocator_traits/members/allocate_hint_nonpod.cc:
Use operator-> to access raw pointer member.
* testsuite/23_containers/vector/59829.cc: Likewise.
* testsuite/23_containers/vector/bool/80893.cc: Likewise.
* testsuite/libstdc++-prettyprinters/cxx11.cc: Use NullablePointer.
* testsuite/util/testsuite_allocator.h (NullablePointer): New 
utility
for tests.
(PointerBase, PointerBase_void): Derive from NullablePointer and use
its constructors and equality operators. Change converting
constructors to use operator-> to access private member of the other
pointer type.
(PointerBase_void::operator->()): Add, for access to private member.
(operator-(PointerBase, PointerBase)): Change to hidden friend.
(operator==(PointerBase, PointerBase)): Remove.
(operator!=(PointerBase, PointerBase)): Remove.

diff --git 
a/libstdc++-v3/testsuite/20_util/allocator_traits/members/allocate_hint_nonpod.cc
 
b/libstdc++-v3/testsuite/20_util/allocator_traits/members/allocate_hint_nonpod.cc
index a5e2a269a15..f9193e83e94 100644
--- 
a/libstdc++-v3/testsuite/20_util/allocator_traits/members/allocate_hint_nonpod.cc
+++ 
b/libstdc++-v3/testsuite/20_util/allocator_traits/members/allocate_hint_nonpod.cc
@@ -45,7 +45,7 @@ struct Alloc
   { return pointer(std::allocator().allocate(n)); }
 
   void deallocate(pointer p, std::size_t n)
-  { std::allocator().deallocate(p.value, n); }
+  { std::allocator().deallocate(p.operator->(), n); }
 };
 
 template
diff --git a/libstdc++-v3/testsuite/23_containers/vector/59829.cc 
b/libstdc++-v3/testsuite/23_containers/vector/59829.cc
index 0e053fa6627..892b9055eb4 100644
--- a/libstdc++-v3/testsuite/23_containers/vector/59829.cc
+++ b/libstdc++-v3/testsuite/23_containers/vector/59829.cc
@@ -51,7 +51,7 @@ struct Alloc
   { return pointer(std::allocator().allocate(n)); }
 
   void deallocate(pointer p, std::size_t n)
-  { std::allocator().deallocate(p.value, n); }
+  { std::allocator().deallocate(p.operator->(), n); }
 };
 
 template
diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/80893.cc 
b/libstdc++-v3/testsuite/23_containers/vector/bool/80893.cc
index f44cdc4a75e..08b15c8d2da 100644
--- a/libstdc++-v3/testsuite/23_containers/vector/bool/80893.cc
+++ b/libstdc++-v3/testsuite/23_containers/vector/bool/80893.cc
@@ -59,7 +59,7 @@ struct Alloc
   void deallocate(pointer p, std::size_t n)
   {
 if (n)
-  std::allocator().deallocate(p.value, n);
+  std::allocator().deallocate(p.operator->(), n);
   }
 };
 
diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc 
b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
index cc588125bdc..c87c8035c45 100644
--- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
+++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include "../util/testsuite_allocator.h" // NullablePointer
 
 typedef std::tuple ExTuple;
 
@@ -59,21 +60,6 @@ struct datum
 
 std::unique_ptr global;
 
-struct Deleter
-{
-  // Deleter is not an empty class:
-  int deleter_member = -1;
-  // But pointer is an empty class:
-  struct pointer
-  {
-pointer(const void* = nullptr) { }
-explicit operator bool() const noexcept { return false; }
-friend bool operator==(pointer, pointer) noexcept { return true; }
-friend bool operator!=(pointer, pointer) noexcept { return false; }
-  };
-  void operator()(pointer) const noexcept { }
-};
-
 

Re: [PATCH] Add __gnu_test::NullablePointer utility to testsuite

2019-05-14 Thread Daniel Krügler
Am Di., 14. Mai 2019 um 13:20 Uhr schrieb Jonathan Wakely :
>
> * testsuite/20_util/allocator_traits/members/allocate_hint_nonpod.cc:
> Use operator-> to access raw pointer member.
> * testsuite/23_containers/vector/59829.cc: Likewise.
> * testsuite/23_containers/vector/bool/80893.cc: Likewise.
> * testsuite/libstdc++-prettyprinters/cxx11.cc: Use NullablePointer.
> * testsuite/util/testsuite_allocator.h (NullablePointer): New utility
> for tests.
> (PointerBase, PointerBase_void): Derive from NullablePointer and use
> its constructors and equality operators. Change converting
> constructors to use operator-> to access private member of the other
> pointer type.
> (PointerBase_void::operator->()): Add, for access to private member.
> (operator-(PointerBase, PointerBase)): Change to hidden friend.
> (operator==(PointerBase, PointerBase)): Remove.
> (operator!=(PointerBase, PointerBase)): Remove.
>
> There are probably more places in the testsuite that could use
> NullablePointer as a minimally-conforming type that meets the
> Cpp17NullablePointer requirements, instead of defining a new type each
> time one is needed.
>
> Tested powerpc64le-linux, committed to trunk.
>

In the primary template of NullablePointer we have:

explicit operator bool() const noexcept { return value == nullptr; }

This is incorrect according to the NullablePointer requirements, it needs to be:

explicit operator bool() const noexcept { return value != nullptr; }

- Daniel


Re: [PATCH] Add __gnu_test::NullablePointer utility to testsuite

2019-05-14 Thread Jonathan Wakely

On 14/05/19 19:09 +0200, Daniel Krügler wrote:

Am Di., 14. Mai 2019 um 13:20 Uhr schrieb Jonathan Wakely :


* testsuite/20_util/allocator_traits/members/allocate_hint_nonpod.cc:
Use operator-> to access raw pointer member.
* testsuite/23_containers/vector/59829.cc: Likewise.
* testsuite/23_containers/vector/bool/80893.cc: Likewise.
* testsuite/libstdc++-prettyprinters/cxx11.cc: Use NullablePointer.
* testsuite/util/testsuite_allocator.h (NullablePointer): New utility
for tests.
(PointerBase, PointerBase_void): Derive from NullablePointer and use
its constructors and equality operators. Change converting
constructors to use operator-> to access private member of the other
pointer type.
(PointerBase_void::operator->()): Add, for access to private member.
(operator-(PointerBase, PointerBase)): Change to hidden friend.
(operator==(PointerBase, PointerBase)): Remove.
(operator!=(PointerBase, PointerBase)): Remove.

There are probably more places in the testsuite that could use
NullablePointer as a minimally-conforming type that meets the
Cpp17NullablePointer requirements, instead of defining a new type each
time one is needed.

Tested powerpc64le-linux, committed to trunk.



In the primary template of NullablePointer we have:

explicit operator bool() const noexcept { return value == nullptr; }

This is incorrect according to the NullablePointer requirements, it needs to be:

explicit operator bool() const noexcept { return value != nullptr; }


Argh! I changed that to test something and then didn't change it back
before committing.

It looks like we need a testsuite for our testsuite utilities.

Fixed with this patch, tested ppc64le-linux and committed to trunk.

Thanks for the diligent checks!


commit 5c5b3801911e4b47dd496ce024840d390b72023b
Author: Jonathan Wakely 
Date:   Tue May 14 20:45:53 2019 +0100

Fix NullablePointer test utility

* testsuite/util/testsuite_allocator.h (NullablePointer::operator bool):
Fix return value.

diff --git a/libstdc++-v3/testsuite/util/testsuite_allocator.h b/libstdc++-v3/testsuite/util/testsuite_allocator.h
index ac7dc8ee2c4..d817ac4e838 100644
--- a/libstdc++-v3/testsuite/util/testsuite_allocator.h
+++ b/libstdc++-v3/testsuite/util/testsuite_allocator.h
@@ -600,7 +600,7 @@ namespace __gnu_test
   NullablePointer() = default;
   NullablePointer(std::nullptr_t) noexcept : value() { }
 
-  explicit operator bool() const noexcept { return value == nullptr; }
+  explicit operator bool() const noexcept { return value != nullptr; }
 
   friend inline bool
   operator==(NullablePointer lhs, NullablePointer rhs) noexcept