[Bug libstdc++/94069] New: [9/10 Regression] <shared_mutex> doesn't compile unless PTHREAD_RWLOCK_INITIALIZER is defined

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Mar 6 11:39:00 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94069

            Bug ID: 94069
           Summary: [9/10 Regression] <shared_mutex> doesn't compile
                    unless PTHREAD_RWLOCK_INITIALIZER is defined
           Product: gcc
           Version: 9.2.1
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: redi at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

If we simulate a target without PTHREAD_RWLOCK_INITIALIZER then <shared_mutex>
cannot be compiled:

#include <pthread.h>
#undef PTHREAD_RWLOCK_INITIALIZER
#include <shared_mutex>

In file included from sm.cc:3:
/home/jwakely/gcc/10/include/c++/10.0.1/shared_mutex: In constructor
'std::__shared_mutex_pthread::__shared_mutex_pthread()':
/home/jwakely/gcc/10/include/c++/10.0.1/shared_mutex:163:57: error: too many
arguments to function 'int std::__glibcxx_rwlock_init(pthread_rwlock_t*)'
  163 |       int __ret = __glibcxx_rwlock_init(&_M_rwlock, NULL);
      |                                                         ^
/home/jwakely/gcc/10/include/c++/10.0.1/shared_mutex:82:3: note: declared here
   82 |   __glibcxx_rwlock_init (pthread_rwlock_t *__rwlock)
      |   ^~~~~~~~~~~~~~~~~~~~~


The code path used when the initializer is not defined needs this fix:

--- a/libstdc++-v3/include/std/shared_mutex
+++ b/libstdc++-v3/include/std/shared_mutex
@@ -160,7 +160,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   public:
     __shared_mutex_pthread()
     {
-      int __ret = __glibcxx_rwlock_init(&_M_rwlock, NULL);
+      int __ret = __glibcxx_rwlock_init(&_M_rwlock);
       if (__ret == ENOMEM)
        __throw_bad_alloc();
       else if (__ret == EAGAIN)


More information about the Gcc-bugs mailing list