[libcxx-commits] [libcxx] [libc++] Enable _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION for Bionic (PR #218055)
Nick Desaulniers via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Aug 21 15:57:22 PDT 2026
https://github.com/nickdesaulniers approved this pull request.
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
```
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;
}
```
https://github.com/llvm/llvm-project/pull/218055
More information about the libcxx-commits
mailing list