This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: 30_threads/thread/native_handle/typesizes.cc is no good


On 10/05/19 19:57 +0100, Iain Sandoe wrote:
Hi Jonathan

On 10 May 2019, at 15:20, Iain Sandoe <idsandoe@googlemail.com> wrote:

On 10 May 2019, at 14:57, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:

Resending as plaint text so the lists don't reject it …

In order to test what it should, we'd need to use an alternate test
function that does not strip off one indirection level from
native_handle_type, if the test is to remain.


Or just adapt the current test to work for the std::thread case too, by
only removing the pointer when we know we need to remove it, as in the
attached patch. Does this work on targets using a pointer type for
pthread_t?

this will fix PR81266, if so, will add to my next run.

The attached minor update to the posted patch does this.
cheers

Sorry for not testing the patch!

The attached version has been committed to trunk.

commit 6c6a062b248be24fd498b5ba184a130904320f11
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri May 10 22:21:40 2019 +0100

    PR libstdc++/81266 fix std::thread::native_handle_type test
    
    The test uses remove_pointer because in most cases native_handle_type is
    a pointer to the actual type that the C++ class contains. However, for
    std::thread, native_handle_type is the same type as the type contained
    in std::thread, and so remove_pointer is not needed. On targets where
    pthread_t is a pointer type remove_pointer<native_handle_type> is not a
    no-op, instead it transforms pthread_t and causes the test to fail.
    
    The fix is to not apply remove_pointer when testing std::thread.
    
            PR libstdc++/81266
            * testsuite/util/thread/all.h: Do not use remove_pointer for
            std::thread::native_handle_type.

diff --git a/libstdc++-v3/testsuite/util/thread/all.h b/libstdc++-v3/testsuite/util/thread/all.h
index e5794fa4a97..2aacae4f2fc 100644
--- a/libstdc++-v3/testsuite/util/thread/all.h
+++ b/libstdc++-v3/testsuite/util/thread/all.h
@@ -25,6 +25,7 @@
 #include <sstream>
 #include <stdexcept>
 #include <type_traits>
+#include <thread>
 
 // C++11 only.
 namespace __gnu_test
@@ -39,7 +40,12 @@ namespace __gnu_test
 
       // Remove possible pointer type.
       typedef typename test_type::native_handle_type native_handle;
-      typedef typename std::remove_pointer<native_handle>::type native_type;
+      // For std::thread native_handle_type is the type of its data member,
+      // for other types it's a pointer to the type of the data member.
+      typedef typename std::conditional<
+	std::is_same<test_type, std::thread>::value,
+	native_handle,
+	typename std::remove_pointer<native_handle>::type>::type native_type;
 
       int st = sizeof(test_type);
       int snt = sizeof(native_type);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]