[libcxx] r304942 - Fix compile error with Bionic's PTHREAD_MUTEX_INITIALIZER
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 7 13:47:43 PDT 2017
Author: ericwf
Date: Wed Jun 7 15:47:42 2017
New Revision: 304942
URL: http://llvm.org/viewvc/llvm-project?rev=304942&view=rev
Log:
Fix compile error with Bionic's PTHREAD_MUTEX_INITIALIZER
On Bionic PTHREAD_MUTEX_INITIALIZER contains the expression "<enum-type> & <integer-type>",
which causes ADL to perform name lookup for operator&. During this lookup Clang decides
that it requires the default member initializer for std::mutex while defining the DMI
for std::mutex::__m_.
If I'm not mistaken this is caused by the explicit noexcept declaration on the defaulted
constructor.
This patch removes the explicit noexcept and instead allows the compiler to declare
the default constructor implicitly noexcept. It also adds a static_assert to ensure
that happens.
Unfortunatly because it's not easy to change the value of _LIBCPP_MUTEX_INITIALIZER
for a single test there is no good way to test this patch.
The Clang behavior causing the trouble here was introduced in r287713, which first
appears in the 4.0 release.
Modified:
libcxx/trunk/include/__mutex_base
libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/default.pass.cpp
Modified: libcxx/trunk/include/__mutex_base
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__mutex_base?rev=304942&r1=304941&r2=304942&view=diff
==============================================================================
--- libcxx/trunk/include/__mutex_base (original)
+++ libcxx/trunk/include/__mutex_base Wed Jun 7 15:47:42 2017
@@ -48,7 +48,7 @@ class _LIBCPP_TYPE_VIS _LIBCPP_THREAD_SA
public:
_LIBCPP_INLINE_VISIBILITY
#ifndef _LIBCPP_CXX03_LANG
- constexpr mutex() _NOEXCEPT = default;
+ constexpr mutex() = default;
#else
mutex() _NOEXCEPT {__m_ = (__libcpp_mutex_t)_LIBCPP_MUTEX_INITIALIZER;}
#endif
@@ -67,6 +67,9 @@ public:
_LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() {return &__m_;}
};
+static_assert(is_nothrow_default_constructible<mutex>::value,
+ "the default constructor for std::mutex must be nothrow");
+
struct _LIBCPP_TYPE_VIS defer_lock_t {};
struct _LIBCPP_TYPE_VIS try_to_lock_t {};
struct _LIBCPP_TYPE_VIS adopt_lock_t {};
Modified: libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/default.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/default.pass.cpp?rev=304942&r1=304941&r2=304942&view=diff
==============================================================================
--- libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/default.pass.cpp (original)
+++ libcxx/trunk/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/default.pass.cpp Wed Jun 7 15:47:42 2017
@@ -16,8 +16,10 @@
// mutex();
#include <mutex>
+#include <type_traits>
int main()
{
+ static_assert(std::is_nothrow_default_constructible<std::mutex>::value, "");
std::mutex m;
}
More information about the cfe-commits
mailing list