[PATCH] D19344: [libc++] fix constexpr error when build with MUSL and macro redef warning when no exception

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 20 21:18:47 PDT 2016

EricWF added inline comments.

Comment at: include/__config:300
@@ -299,3 +299,3 @@
-#if !(__has_feature(cxx_exceptions))
+#if !(__has_feature(cxx_exceptions)) && !defined(_LIBCPP_NO_EXCEPTIONS)
weimingz wrote:
> Is this change OK?

Comment at: include/__mutex_base:43
@@ -42,3 +42,3 @@
      constexpr mutex() _NOEXCEPT : __m_(PTHREAD_MUTEX_INITIALIZER) {}
weimingz wrote:
> EricWF wrote:
> > This is not OK. It's critical that mutex have a constexpr constructor that it runs during the "Constant initialization" phase of static initialization.
> > Heres an example of the difference this makes: https://godbolt.org/g/3cvlMJ
> > 
> > Also the constructor is specified as being constexpr in C++11. We can't turn that off. 
> > 
> > If one particular pthread implementation is broken then we need a fix targeted to only that implementation.  However this seems like a pthread bug and not a libc++ bug.
> The macro has an "#else" part.  I'm not familiar with this, but it seems the constexpr an "optional feature".
So `_LIBCPP_HAS_NO_CONSTEXPR` checks for the presence of C++11 constexpr semantics. In C++14 support for `constexpr` was greatly increased, allowing many more expressions to be considered "constant expressions".  The original macro, and `_LIBCPP_HAS_NO_CXX14_CONSTXPR` check if a compiler has completely implemented the C++11 or C++14 constexpr requirements respectively. In your case `PTHREAD_MUTEX_INITIALIZER` is defined in such a way that it requires the C++14 definition of `constexpr`. 


More information about the cfe-commits mailing list