Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[libc++] LWG4169: std::atomic<T>'s default constructor should be constrained #131950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
Loading
from

Conversation

frederick-vs-ja
Copy link
Contributor

@frederick-vs-ja frederick-vs-ja commented Mar 19, 2025

Drive-by: Rename constexpr_noexcept.compile.pass.cpp to default_constructor.compile.pass.cpp as test coverage is added to it, and compile it in all modes.

Fixes #118367.

@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner March 19, 2025 01:39
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Mar 19, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 19, 2025

@llvm/pr-subscribers-libcxx

Author: A. Jiang (frederick-vs-ja)

Changes

Drive-by: Rename constexpr_noexcept.compile.pass.cpp to default_constructor.compile.pass.cpp as test coverage is added to it, and compile it in all modes.

Fixes #118367.


Full diff: https://github.com/llvm/llvm-project/pull/131950.diff

4 Files Affected:

  • (modified) libcxx/docs/Status/Cxx2cIssues.csv (+1-1)
  • (modified) libcxx/include/__atomic/atomic.h (+3-1)
  • (removed) libcxx/test/std/atomics/atomics.types.generic/constexpr_noexcept.compile.pass.cpp (-41)
  • (added) libcxx/test/std/atomics/atomics.types.generic/default_constructor.compile.pass.cpp (+60)
diff --git a/libcxx/docs/Status/Cxx2cIssues.csv b/libcxx/docs/Status/Cxx2cIssues.csv
index 9bf31c417f3c9..66d286fd6c38c 100644
--- a/libcxx/docs/Status/Cxx2cIssues.csv
+++ b/libcxx/docs/Status/Cxx2cIssues.csv
@@ -108,7 +108,7 @@
 "`LWG4154 <https://wg21.link/LWG4154>`__","The Mandates for ``std::packaged_task``'s constructor from a callable entity should consider decaying","2024-11 (Wrocław)","","",""
 "`LWG4157 <https://wg21.link/LWG4157>`__","The resolution of LWG3465 was damaged by P2167R3","2024-11 (Wrocław)","","20",""
 "`LWG4164 <https://wg21.link/LWG4164>`__","Missing guarantees for ``forward_list`` modifiers","2024-11 (Wrocław)","","",""
-"`LWG4169 <https://wg21.link/LWG4169>`__","``std::atomic<T>``'s default constructor should be constrained","2024-11 (Wrocław)","","",""
+"`LWG4169 <https://wg21.link/LWG4169>`__","``std::atomic<T>``'s default constructor should be constrained","2024-11 (Wrocław)","|Complete|","21",""
 "`LWG4170 <https://wg21.link/LWG4170>`__","``contiguous_iterator`` should require ``to_address(I{})``","2024-11 (Wrocław)","","",""
 "","","","","",""
 "`LWG3578 <https://wg21.link/3578>`__","Iterator SCARYness in the context of associative container merging","2025-02 (Hagenberg)","","",""
diff --git a/libcxx/include/__atomic/atomic.h b/libcxx/include/__atomic/atomic.h
index c65f9afe4f390..0cabd4d198e66 100644
--- a/libcxx/include/__atomic/atomic.h
+++ b/libcxx/include/__atomic/atomic.h
@@ -235,7 +235,9 @@ struct atomic : public __atomic_base<_Tp> {
   using __base _LIBCPP_NODEBUG = __atomic_base<_Tp>;
 
 #if _LIBCPP_STD_VER >= 20
-  _LIBCPP_HIDE_FROM_ABI atomic() = default;
+  _LIBCPP_HIDE_FROM_ABI atomic()
+    requires is_default_constructible_v<_Tp>
+  = default;
 #else
   _LIBCPP_HIDE_FROM_ABI atomic() _NOEXCEPT = default;
 #endif
diff --git a/libcxx/test/std/atomics/atomics.types.generic/constexpr_noexcept.compile.pass.cpp b/libcxx/test/std/atomics/atomics.types.generic/constexpr_noexcept.compile.pass.cpp
deleted file mode 100644
index fca52a998eace..0000000000000
--- a/libcxx/test/std/atomics/atomics.types.generic/constexpr_noexcept.compile.pass.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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: c++03, c++11, c++14, c++17
-
-#include <atomic>
-#include <type_traits>
-
-#include "test_macros.h"
-
-template <typename T>
-constexpr bool test() {
-  [[maybe_unused]] constexpr T a;
-  static_assert(std::is_nothrow_constructible_v<T>);
-  ASSERT_NOEXCEPT(T{});
-  return true;
-}
-
-struct throwing {
-  throwing() {}
-};
-
-struct trivial {
-  int a;
-};
-
-void test() {
-  static_assert(test<std::atomic<bool>>());
-  static_assert(test<std::atomic<int>>());
-  static_assert(test<std::atomic<int*>>());
-  static_assert(test<std::atomic<trivial>>());
-  static_assert(test<std::atomic_flag>());
-
-  static_assert(!std::is_nothrow_constructible_v<std::atomic<throwing>>);
-  ASSERT_NOT_NOEXCEPT(std::atomic<throwing>{});
-}
diff --git a/libcxx/test/std/atomics/atomics.types.generic/default_constructor.compile.pass.cpp b/libcxx/test/std/atomics/atomics.types.generic/default_constructor.compile.pass.cpp
new file mode 100644
index 0000000000000..6d6e9e8d223a1
--- /dev/null
+++ b/libcxx/test/std/atomics/atomics.types.generic/default_constructor.compile.pass.cpp
@@ -0,0 +1,60 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include <atomic>
+#include <type_traits>
+
+#include "test_macros.h"
+
+template <typename T>
+void test() {
+#if TEST_STD_VER >= 11
+  constexpr T a{};
+  (void)a;
+#  if TEST_STD_VER >= 20
+  [[maybe_unused]] constexpr T b;
+#  endif
+#else
+  T a;
+  (void)a;
+#endif
+  static_assert(std::is_nothrow_constructible<T>::value, "");
+  ASSERT_NOEXCEPT(T{});
+}
+
+struct throwing {
+  throwing() {}
+};
+
+struct trivial {
+  int a;
+};
+
+struct not_default_constructible {
+  explicit not_default_constructible(int) {}
+};
+
+void test() {
+  test<std::atomic<bool> >();
+  test<std::atomic<int> >();
+  test<std::atomic<int*> >();
+  test<std::atomic<trivial> >();
+  test<std::atomic_flag>();
+
+#if TEST_STD_VER >= 20
+  static_assert(!std::is_nothrow_constructible_v<std::atomic<throwing>>);
+  ASSERT_NOT_NOEXCEPT(std::atomic<throwing>{});
+
+  static_assert(!std::is_default_constructible_v<std::atomic<not_default_constructible>>);
+#else
+  static_assert(std::is_nothrow_constructible<std::atomic<throwing> >::value, "");
+  ASSERT_NOEXCEPT(std::atomic<throwing>{});
+
+  static_assert(std::is_default_constructible<std::atomic<not_default_constructible> >::value, "");
+#endif
+}

@frederick-vs-ja frederick-vs-ja force-pushed the lwg-4169 branch 4 times, most recently from 3dfa2aa to 960c240 Compare March 19, 2025 05:41
Drive-by: Rename `constexpr_noexcept.compile.pass.cpp` to
`default_constructor.compile.pass.cpp` as test coverage is added to it,
and run it in all modes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LWG4169: std::atomic<T>'s default constructor should be constrained
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.