Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2226646/?format=api
{ "id": 2226646, "url": "http://patchwork.ozlabs.org/api/patches/2226646/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/bmm.hhunfc5mlg.gcc.gcc-TEST.peppe.36.1.1@forge-stage.sourceware.org/", "project": { "id": 17, "url": "http://patchwork.ozlabs.org/api/projects/17/?format=api", "name": "GNU Compiler Collection", "link_name": "gcc", "list_id": "gcc-patches.gcc.gnu.org", "list_email": "gcc-patches@gcc.gnu.org", "web_url": null, "scm_url": null, "webscm_url": null, "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<bmm.hhunfc5mlg.gcc.gcc-TEST.peppe.36.1.1@forge-stage.sourceware.org>", "list_archive_url": null, "date": "2026-04-22T17:47:28", "name": "[v1,1/1] libstdc++: constrain std::atomic's default constructor", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "fd5a6e9eefb4400839b07487aa265a9dc88c10ec", "submitter": { "id": 93222, "url": "http://patchwork.ozlabs.org/api/people/93222/?format=api", "name": "peppe via Sourceware Forge", "email": "forge-bot+peppe@forge-stage.sourceware.org" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/gcc/patch/bmm.hhunfc5mlg.gcc.gcc-TEST.peppe.36.1.1@forge-stage.sourceware.org/mbox/", "series": [ { "id": 501056, "url": "http://patchwork.ozlabs.org/api/series/501056/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=501056", "date": "2026-04-22T17:47:28", "name": "WIP: libstdc++: constrain std::atomic's default constructor", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/501056/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2226646/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2226646/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>", "X-Original-To": [ "incoming@patchwork.ozlabs.org", "gcc-patches@gcc.gnu.org" ], "Delivered-To": [ "patchwork-incoming@legolas.ozlabs.org", "gcc-patches@gcc.gnu.org" ], "Authentication-Results": [ "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)", "sourceware.org; dmarc=none (p=none dis=none)\n header.from=forge-stage.sourceware.org", "sourceware.org;\n spf=pass smtp.mailfrom=forge-stage.sourceware.org", "server2.sourceware.org;\n arc=none smtp.remote-ip=38.145.34.39" ], "Received": [ "from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g16DR3QrVz1yD5\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 23 Apr 2026 03:49:26 +1000 (AEST)", "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id CEE8A4B920D0\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 22 Apr 2026 17:49:23 +0000 (GMT)", "from forge-stage.sourceware.org (vm08.sourceware.org [38.145.34.39])\n by sourceware.org (Postfix) with ESMTPS id 2B67D4BB5897\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 17:48:22 +0000 (GMT)", "from forge-stage.sourceware.org (localhost [IPv6:::1])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256)\n (No client certificate requested)\n by forge-stage.sourceware.org (Postfix) with ESMTPS id F03C642BF5\n for <gcc-patches@gcc.gnu.org>; Wed, 22 Apr 2026 17:48:21 +0000 (UTC)" ], "DKIM-Filter": [ "OpenDKIM Filter v2.11.0 sourceware.org CEE8A4B920D0", "OpenDKIM Filter v2.11.0 sourceware.org 2B67D4BB5897" ], "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org 2B67D4BB5897", "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org 2B67D4BB5897", "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776880102; cv=none;\n b=Gj3zi6Jrkp3t1bJKTgxjLxcUy4jXv8Rgo9SNarhrsoOD5dlh6MVPG+8nIMqtLjsysTz0XE66+IZUa0KElC8P0HKwSy/Uu8qVv/yiu/suUVdLuKIOOmPRXtJIIJ6AqTaQa9gOLSCyK5BUHJElRWHRcHBmVDxpRb2k1ixgoYdFteY=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776880102; c=relaxed/simple;\n bh=oqE/6QPoaWaqH67rB6kvvyUohQt7bs+o7RYYxCH5X10=;\n h=From:Date:Subject:To:Message-ID;\n b=H15dhzveno8t6Dl9xKTZCdQz1i+Gu2dTrs0J4IxGE6QdZHJ9lZwMUkY0z7oQ6hjRS6A3zqiQa4lCq1jhL00a7fnsKm4YFEZRTjentxrmtUFUNwlD/7ky4B75z/0E7P5WBIU6H4IQ7oGDwU1Wum9t+urwaqeMhFfZ1mJ9kNRIfe8=", "ARC-Authentication-Results": "i=1; server2.sourceware.org", "From": "peppe via Sourceware Forge <forge-bot+peppe@forge-stage.sourceware.org>", "Date": "Wed, 22 Apr 2026 17:47:28 +0000", "Subject": "[PATCH v1 1/1] libstdc++: constrain std::atomic's default constructor", "To": "gcc-patches mailing list <gcc-patches@gcc.gnu.org>", "Message-ID": "\n <bmm.hhunfc5mlg.gcc.gcc-TEST.peppe.36.1.1@forge-stage.sourceware.org>", "X-Mailer": "batrachomyomachia", "X-Requested-Reviewer": "redi", "X-Pull-Request-Organization": "gcc", "X-Pull-Request-Repository": "gcc-TEST", "X-Pull-Request": "https://forge.sourceware.org/gcc/gcc-TEST/pulls/36", "References": "\n <bmm.hhunfc5mlg.gcc.gcc-TEST.peppe.36.1.0@forge-stage.sourceware.org>", "In-Reply-To": "\n <bmm.hhunfc5mlg.gcc.gcc-TEST.peppe.36.1.0@forge-stage.sourceware.org>", "X-Patch-URL": "\n https://forge.sourceware.org/peppe/gcc-TEST/commit/50befa32f7cc696850607d9c09b81a4de529597a", "X-BeenThere": "gcc-patches@gcc.gnu.org", "X-Mailman-Version": "2.1.30", "Precedence": "list", "List-Id": "Gcc-patches mailing list <gcc-patches.gcc.gnu.org>", "List-Unsubscribe": "<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>", "List-Archive": "<https://gcc.gnu.org/pipermail/gcc-patches/>", "List-Post": "<mailto:gcc-patches@gcc.gnu.org>", "List-Help": "<mailto:gcc-patches-request@gcc.gnu.org?subject=help>", "List-Subscribe": "<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>", "Reply-To": "gcc-patches mailing list <gcc-patches@gcc.gnu.org>,\n peppe@noreply.localhost", "Errors-To": "gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org" }, "content": "From: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>\n\nThis commit implements the proposed resolution to LWG4169, which is\nto constrain std::atomic<T>'s default constructor based on whether\nT itself is default constructible.\n\nAt the moment, std::atomic<T>'s primary template in libstdc++ has a\ndefaulted default constructor. Value-initialization of the T member\n(since C++20 / P0883R2) is done via a NSDMI (= T()).\n\nGCC already considers the defaulted constructor constrained/deleted,\nhowever this behavior is non-standard (see the discussion in PR116769):\nthe presence of a NSDMI should not make the constructor unavailable to\noverload resolution/deleted ([class.default.ctor]/2.5 does not apply).\nWhen using libstdc++ on Clang, this causes build issues as the\nconstructor is *not* deleted there -- the interpretation of\n[class.default.ctor]/4 seems to match Clang's behavior.\n\nTherefore, although there would be \"nothing to do\" with GCC+libstdc++,\nthis commit changes the code as to stop relying on the GCC language\nextension. In C++ >= 20 modes, std::atomic's defaulted default\nconstructor is changed to be a non-defaulted one, with a constraint\nadded as per LWG4169; value-initialization of the data member is moved\nfrom the NSDMI to the member init list. The new signature matches the\none in the Standard as per [atomics.types.operations]/1.\n\nIn pre-C++20 modes, the constructor is left defaulted. This ensures\ncompatibility with C++11/14/17 behavior. In other words: we are not\nbackporting P0883R2 to earlier language modes here.\n\nAmend an existing test to check that a std::atomic wrapping a\nnon-default constructible type is always non-default constructible:\nfrom C++20, because of the constraint; before C++20, because we\nare removing the NSDMI, and therefore [class.default.ctor]/2.5\napplies.\n\nAdd another test that checks that std::atomic is trivially default\nconstructible in pre-C++20 modes, and it isn't afterwards.\n\nlibstdc++-v3/ChangeLog:\n\n\t* include/bits/version.def (atomic_value_initialization):\n\tGuard the FTM with the language concepts FTM.\n\t* include/bits/version.h: Regenerate.\n\t* include/std/atomic (atomic): When atomic value init is\n\tdefined, change the defaulted default constructor to\n\ta non-defaulted one, constraining it as per LWG4169.\n\tOtherwise, keep the existing constructor.\n\tRemove the NSDMI for the _M_i member.\n\t(_GLIBCXX20_INIT): Drop the macro, as it is not needed any more.\n\t* testsuite/29_atomics/atomic/69301.cc: Test that\n\tan atomic wrapping a non-default-constructible type is\n\talways itself non-default-constructible (in all language\n\tmodes).\n\t* testsuite/29_atomics/atomic/cons/trivial.cc: New test.\n---\n libstdc++-v3/include/bits/version.def | 1 +\n libstdc++-v3/include/bits/version.h | 2 +-\n libstdc++-v3/include/std/atomic | 22 +++++-----\n .../testsuite/29_atomics/atomic/69301.cc | 2 +\n .../29_atomics/atomic/cons/trivial.cc | 41 +++++++++++++++++++\n 5 files changed, 57 insertions(+), 11 deletions(-)\n create mode 100644 libstdc++-v3/testsuite/29_atomics/atomic/cons/trivial.cc", "diff": "diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def\nindex 2af5a54bff28..56638759539b 100644\n--- a/libstdc++-v3/include/bits/version.def\n+++ b/libstdc++-v3/include/bits/version.def\n@@ -770,6 +770,7 @@ ftms = {\n values = {\n v = 201911;\n cxxmin = 20;\n+ extra_cond = \"__cpp_concepts >= 201907L\";\n };\n };\n \ndiff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h\nindex 9833023cfdc8..29e1535298cb 100644\n--- a/libstdc++-v3/include/bits/version.h\n+++ b/libstdc++-v3/include/bits/version.h\n@@ -856,7 +856,7 @@\n #undef __glibcxx_want_atomic_ref\n \n #if !defined(__cpp_lib_atomic_value_initialization)\n-# if (__cplusplus >= 202002L)\n+# if (__cplusplus >= 202002L) && (__cpp_concepts >= 201907L)\n # define __glibcxx_atomic_value_initialization 201911L\n # if defined(__glibcxx_want_all) || defined(__glibcxx_want_atomic_value_initialization)\n # define __cpp_lib_atomic_value_initialization 201911L\ndiff --git a/libstdc++-v3/include/std/atomic b/libstdc++-v3/include/std/atomic\nindex cd08df34ba77..9b1aca0fc09a 100644\n--- a/libstdc++-v3/include/std/atomic\n+++ b/libstdc++-v3/include/std/atomic\n@@ -51,6 +51,7 @@\n \n #include <bits/atomic_base.h>\n #include <cstdint>\n+#include <type_traits>\n \n namespace std _GLIBCXX_VISIBILITY(default)\n {\n@@ -189,14 +190,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n #endif // __cpp_lib_atomic_wait\n };\n \n-/// @cond undocumented\n-#if __cpp_lib_atomic_value_initialization\n-# define _GLIBCXX20_INIT(I) = I\n-#else\n-# define _GLIBCXX20_INIT(I)\n-#endif\n-/// @endcond\n-\n /**\n * @brief Generic atomic type, primary class template.\n *\n@@ -216,7 +209,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n static constexpr int _S_alignment\n = _S_min_alignment > alignof(_Tp) ? _S_min_alignment : alignof(_Tp);\n \n- alignas(_S_alignment) _Tp _M_i _GLIBCXX20_INIT(_Tp());\n+ alignas(_S_alignment) _Tp _M_i;\n \n static_assert(__is_trivially_copyable(_Tp),\n \t\t \"std::atomic requires a trivially copyable type\");\n@@ -232,7 +225,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n #endif\n \n public:\n+#if __cpp_lib_atomic_value_initialization\n+ // _GLIBCXX_RESOLVE_LIB_DEFECTS\n+ // 4169. std::atomic<T>'s default constructor should be constrained\n+ constexpr atomic() noexcept(is_nothrow_default_constructible_v<_Tp>)\n+\trequires is_default_constructible_v<_Tp>\n+\t: _M_i()\n+ {}\n+#else\n atomic() = default;\n+#endif\n+\n ~atomic() noexcept = default;\n atomic(const atomic&) = delete;\n atomic& operator=(const atomic&) = delete;\n@@ -414,7 +417,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n #endif // __cpp_lib_atomic_wait\n \n };\n-#undef _GLIBCXX20_INIT\n \n /// Partial specialization for pointer types.\n template<typename _Tp>\ndiff --git a/libstdc++-v3/testsuite/29_atomics/atomic/69301.cc b/libstdc++-v3/testsuite/29_atomics/atomic/69301.cc\nindex da54b0e259ef..72bf4af6af30 100644\n--- a/libstdc++-v3/testsuite/29_atomics/atomic/69301.cc\n+++ b/libstdc++-v3/testsuite/29_atomics/atomic/69301.cc\n@@ -29,6 +29,8 @@ struct NonDefaultConstructible\n \n template class std::atomic<NonDefaultConstructible>;\n \n+static_assert(!std::is_default_constructible<std::atomic<NonDefaultConstructible>>::value);\n+\n void\n test01()\n {\ndiff --git a/libstdc++-v3/testsuite/29_atomics/atomic/cons/trivial.cc b/libstdc++-v3/testsuite/29_atomics/atomic/cons/trivial.cc\nnew file mode 100644\nindex 000000000000..bb578db362df\n--- /dev/null\n+++ b/libstdc++-v3/testsuite/29_atomics/atomic/cons/trivial.cc\n@@ -0,0 +1,41 @@\n+// { dg-do compile { target c++11 } }\n+\n+#include <atomic>\n+#include <type_traits>\n+\n+// C++20 / P0883R2 makes std::atomic value-initialize, so it's no\n+// longer going to be trivially default constructible; check that it\n+// still is in earlier language modes.\n+// (We are not applying that paper as a DR.)\n+#if __cpp_lib_atomic_value_initialization\n+constexpr bool atomic_default_ctor_is_trivial = false;\n+#else\n+constexpr bool atomic_default_ctor_is_trivial = true;\n+#endif\n+\n+template<typename T>\n+using isTDC = std::is_trivially_default_constructible<T>;\n+\n+static_assert(isTDC<std::atomic<bool>>::value == atomic_default_ctor_is_trivial);\n+static_assert(isTDC<std::atomic<char>>::value == atomic_default_ctor_is_trivial);\n+static_assert(isTDC<std::atomic<unsigned char>>::value == atomic_default_ctor_is_trivial);\n+static_assert(isTDC<std::atomic<int>>::value == atomic_default_ctor_is_trivial);\n+static_assert(isTDC<std::atomic<long>>::value == atomic_default_ctor_is_trivial);\n+static_assert(isTDC<std::atomic<unsigned long long>>::value == atomic_default_ctor_is_trivial);\n+static_assert(isTDC<std::atomic<int*>>::value == atomic_default_ctor_is_trivial);\n+\n+struct DefaultConstructible\n+{\n+ int a;\n+ long long b;\n+ char* p;\n+};\n+static_assert(isTDC<std::atomic<DefaultConstructible>>::value == atomic_default_ctor_is_trivial);\n+\n+struct NonDefaultConstructible\n+{\n+ NonDefaultConstructible(int i) : val(i) { }\n+ int val;\n+};\n+// Not default constructible, therefore not trivially default constructible\n+static_assert(isTDC<std::atomic<NonDefaultConstructible>>::value == false);\n", "prefixes": [ "v1", "1/1" ] }