[libcxx-commits] [libcxx] [libc++] Enable _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION for Bionic (PR #218055)
via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Aug 31 13:51:20 PDT 2026
enh-google wrote:
> Looks good to me. I asked Gemini what unit tests for this might look like; consider adding them:
>
> AI comment below:
>
> Purpose: standard C++ does not require mutex to have a trivial destructor (and platforms like Darwin intentionally do not support it due to D64298):
>
> ```c++
> //===----------------------------------------------------------------------===//
> //
> // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
> // See https://llvm.org/LICENSE.txt for license information.
> // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
> //
> //===----------------------------------------------------------------------===//
>
> // UNSUPPORTED: no-threads
>
> // <mutex>
>
> // class mutex;
>
> // Test that std::mutex has trivial destruction when and only when
> // _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION is enabled.
>
> #include <mutex>
> #include <type_traits>
>
> #include "test_macros.h"
>
> #if _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
> static_assert(std::is_trivially_destructible<std::mutex>::value, "");
> #else
> static_assert(!std::is_trivially_destructible<std::mutex>::value, "");
> #endif
> ```
i don't think this makes sense because the [possibly] problematic code is opaque to c++.
> Purpose: Verifies that static/global instances do not trigger exit-time destructor diagnostics on platforms with _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION:
>
> ```c++
> //===----------------------------------------------------------------------===//
> //
> // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
> // See https://llvm.org/LICENSE.txt for license information.
> // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
> //
> //===----------------------------------------------------------------------===//
>
> // UNSUPPORTED: no-threads
> // ADDITIONAL_COMPILE_FLAGS: -Wexit-time-destructors -Werror
>
> // <mutex>
>
> #include <mutex>
>
> #if _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
> static std::mutex global_mutex;
> #endif
>
> int main(int, char**) {
> #if _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
> static std::mutex local_mutex;
> (void)local_mutex;
> #endif
> return 0;
> }
> ```
this seems pointless?
https://github.com/llvm/llvm-project/pull/218055
More information about the libcxx-commits
mailing list