From patchwork Wed Nov 2 13:40:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 14236 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3626962wru; Wed, 2 Nov 2022 06:43:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM52X8uq6lIu1Vv/iaQjoSLURzOp5FiYcHgTmR7OFkpmHwhI68IynpsCOqtCIWtPY0w0t5eA X-Received: by 2002:a17:906:5f8a:b0:7ad:ca14:3ae with SMTP id a10-20020a1709065f8a00b007adca1403aemr17856840eju.509.1667396626533; Wed, 02 Nov 2022 06:43:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667396626; cv=none; d=google.com; s=arc-20160816; b=bxxFQ2pBnae4KT/ihH0xBI13ct0axwi4o8PTE4UNOzrAghBs3hi/s9f1RcWp37bIEX 9h8xXlXMa5YiPpdmSx+TgcR5SKSacj3uqmUnnfRRP8N1a1UZMBIQDvF9dxFa1Si1dB7F W5al9oATJ+pMBF0jK8jeR1qCQrz+lZ0+7y20767WX91+rK/uQGx/yZelz69fcOd+mAwh qF2FN7MpCTX/3iBZ26cLfrpFGT1kTl9yo55v+iEj1uGWzIX0EP087RAKMzKcyKNRNdxA y1gx739NfesngUg5GMmWgr03nSCz002iJlvJqbcm78jTF2esOJm1hPUjeNkBkKIq7aGi jbLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=PwjDy7Lw59lqCQ1Lm4yoR7Lau22+1HI6TntyR3U5/No=; b=FNaqkH/89NsC/MWxJlVCt8bWW8Y91ZpzTsNsNzBfFnbFg7WU9ne9JFUyBSLN3SelNZ wqGDLkqeHRWxukV7aSEjdcVfrzzfzBBTcdBiHwwzYTvSrJoXkXQSFWhsnycmxI8ALdZ9 2quEeB3jBmL0Vd0vmmvWDTWzmH0wmuiuD8DMmD/wV4PYF0Mq8Bgp0kB0VcFpe3ohw0UP sftApo01qhM1WbgiY6gVgka3rm8L7de72f+7r43yXRRNig261foeqLgzs32USzs/GJao WdMYHYs0FthpDqPJQO7H69QEkjAb3AlKIyilygzEi7w3wxQR/xgp1gQgqpJJ0J29kvme PD0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=I5UEJqVL; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id he12-20020a1709073d8c00b0072b0f6f1456si18513721ejc.612.2022.11.02.06.43.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 06:43:46 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=I5UEJqVL; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A8C5A3857368 for ; Wed, 2 Nov 2022 13:43:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A8C5A3857368 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667396590; bh=PwjDy7Lw59lqCQ1Lm4yoR7Lau22+1HI6TntyR3U5/No=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=I5UEJqVLHw10WjIIpVQHa5jEzkwSMGwZSYDitXX9jSEYJeQm2Hgaiht3Uv+Q4JNoN ersQA2L2USShXcRE130bsXwNs/p/UJb43HWIITZEKyvKdkDI2RGXs8iz99sWXH2N3D GTfaTMOC0oPhQkW+G8OWOM8SFYi3SgwtORsBczhU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E255D3858CDA for ; Wed, 2 Nov 2022 13:41:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E255D3858CDA Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-550--wzj7ifkP-e6Wrgnuf2uLQ-1; Wed, 02 Nov 2022 09:41:19 -0400 X-MC-Unique: -wzj7ifkP-e6Wrgnuf2uLQ-1 Received: by mail-qv1-f72.google.com with SMTP id b2-20020a0cfe62000000b004bbfb15297dso4856486qvv.19 for ; Wed, 02 Nov 2022 06:41:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PwjDy7Lw59lqCQ1Lm4yoR7Lau22+1HI6TntyR3U5/No=; b=trHRWcofwq04kFrhVZ6E6AxkSONRzIemXewtQkdP8gwLS5ES5GaFb2WWUQHgx4CQbS e6C12bGhB5nMYuvjTQ++dOFSFCx7i0WtbR2zoMpfKpxU7H9lUuN0O86tAoS6ZrItTUQ8 9yN9DDTiDhI/lnvuNLA/2C7tTb0bQitSpeJm9ZFcd/3sXgCwwpnXlVFgvjR6Rv8BqBSW 7GIgPEj4hvb5ADVUWNFzYobK3mGFFe554MpI1FUs/RMPY5h2VWNmMIQJswGNhjSfu+zx wH9UFsWVm/Z1l7QEfM7L4bvr4wzDHojkQB29NCR1A7hgZX9nhhs5wLO9UZ836a+RAvC+ fdMw== X-Gm-Message-State: ACrzQf3jZvp5HJ6tzAVzhYtaIieRJlR0Usd2+PbfCKiXRCCHRn8NbAr4 KZ46MCIHBoIep+AKS0TNDWADwnN7/3RfHNR91xDj/9f8IzPZOBFvDrTr3f3TkzTyjHvtN6lq21i JcGdYxNVh4GIbKdQufr2uKpKpIp64+bV973T2ioXUr6XAVr34XddgoM/s5rPA1jgk4h0= X-Received: by 2002:a05:620a:12cc:b0:6fa:2e4d:cfdd with SMTP id e12-20020a05620a12cc00b006fa2e4dcfddmr11804861qkl.375.1667396478095; Wed, 02 Nov 2022 06:41:18 -0700 (PDT) X-Received: by 2002:a05:620a:12cc:b0:6fa:2e4d:cfdd with SMTP id e12-20020a05620a12cc00b006fa2e4dcfddmr11804817qkl.375.1667396477571; Wed, 02 Nov 2022 06:41:17 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id dm45-20020a05620a1d6d00b006e8f8ca8287sm8640758qkb.120.2022.11.02.06.41.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 06:41:17 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] libstdc++: Declare const global variables inline Date: Wed, 2 Nov 2022 09:40:28 -0400 Message-Id: <20221102134028.1032216-1-ppalka@redhat.com> X-Mailer: git-send-email 2.38.1.381.gc03801e19c MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Cc: libstdc++@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748392085057883517?= X-GMAIL-MSGID: =?utf-8?q?1748392085057883517?= IIUC such variables should be declared inline to avoid potential ODR violations since they're otherwise considered to be distinct (internal linkage) entities across TUs. The changes inside the regex_constants and execution namespace seem to be unimplemented parts of P0607R0; the rest of the changes touch only implementation details. Tested on x86_64-pc-linux-gnu, does this look OK for trunk? libstdc++-v3/ChangeLog: * include/bits/atomic_wait.h (_detail::__platform_wait_alignment): Declare inline. Remove redundant static specifier. (__detail::__atomic_spin_count_relax): Declare inline. (__detail::__atomic_spin_count): Likewise. * include/bits/regex_automaton.h (__detail::_S_invalid_state_id): Conditionally declare inline. Declare constexpr. Remove redundant const and static specifiers. * include/bits/regex_error.h (regex_constants::error_collate): Conditionally declare inline. (regex_constants::error_ctype): Likewise. (regex_constants::error_escape): Likewise. (regex_constants::error_backref): Likewise. (regex_constants::error_brack): Likewise. (regex_constants::error_paren): Likewise. (regex_constants::error_brace): Likewise. (regex_constants::error_badbrace): Likewise. (regex_constants::error_range): Likewise. (regex_constants::error_space): Likewise. (regex_constants::error_badrepeat): Likewise. (regex_constants::error_complexity): Likewise. (regex_constants::error_stack): Likewise. * include/ext/concurrence.h (__gnu_cxx::__default_lock_policy): Likewise. Remove redundant static specifier. * include/pstl/execution_defs.h (execution::seq): Conditionally declare inline. (execution::par): Likewise. (execution::par_unseq): Likewise. (execution::unseq): Likewise. --- libstdc++-v3/include/bits/atomic_wait.h | 8 +++---- libstdc++-v3/include/bits/regex_automaton.h | 2 +- libstdc++-v3/include/bits/regex_error.h | 26 ++++++++++----------- libstdc++-v3/include/ext/concurrence.h | 2 +- libstdc++-v3/include/pstl/execution_defs.h | 8 +++---- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/libstdc++-v3/include/bits/atomic_wait.h b/libstdc++-v3/include/bits/atomic_wait.h index 76ed7409937..bd1ed56d157 100644 --- a/libstdc++-v3/include/bits/atomic_wait.h +++ b/libstdc++-v3/include/bits/atomic_wait.h @@ -58,14 +58,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifdef _GLIBCXX_HAVE_LINUX_FUTEX #define _GLIBCXX_HAVE_PLATFORM_WAIT 1 using __platform_wait_t = int; - static constexpr size_t __platform_wait_alignment = 4; + inline constexpr size_t __platform_wait_alignment = 4; #else // define _GLIBCX_HAVE_PLATFORM_WAIT and implement __platform_wait() // and __platform_notify() if there is a more efficient primitive supported // by the platform (e.g. __ulock_wait()/__ulock_wake()) which is better than // a mutex/condvar based wait. using __platform_wait_t = uint64_t; - static constexpr size_t __platform_wait_alignment + inline constexpr size_t __platform_wait_alignment = __alignof__(__platform_wait_t); #endif } // namespace __detail @@ -142,8 +142,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif } - constexpr auto __atomic_spin_count_relax = 12; - constexpr auto __atomic_spin_count = 16; + inline constexpr auto __atomic_spin_count_relax = 12; + inline constexpr auto __atomic_spin_count = 16; struct __default_spin_policy { diff --git a/libstdc++-v3/include/bits/regex_automaton.h b/libstdc++-v3/include/bits/regex_automaton.h index f95eb7dad6d..44bde42e212 100644 --- a/libstdc++-v3/include/bits/regex_automaton.h +++ b/libstdc++-v3/include/bits/regex_automaton.h @@ -46,7 +46,7 @@ namespace __detail */ typedef long _StateIdT; - static const _StateIdT _S_invalid_state_id = -1; + _GLIBCXX17_INLINE constexpr _StateIdT _S_invalid_state_id = -1; template using _Matcher = std::function; diff --git a/libstdc++-v3/include/bits/regex_error.h b/libstdc++-v3/include/bits/regex_error.h index 74a1428c2c7..ab207650d44 100644 --- a/libstdc++-v3/include/bits/regex_error.h +++ b/libstdc++-v3/include/bits/regex_error.h @@ -66,60 +66,60 @@ namespace regex_constants }; /** The expression contained an invalid collating element name. */ - constexpr error_type error_collate(_S_error_collate); + _GLIBCXX17_INLINE constexpr error_type error_collate(_S_error_collate); /** The expression contained an invalid character class name. */ - constexpr error_type error_ctype(_S_error_ctype); + _GLIBCXX17_INLINE constexpr error_type error_ctype(_S_error_ctype); /** * The expression contained an invalid escaped character, or a trailing * escape. */ - constexpr error_type error_escape(_S_error_escape); + _GLIBCXX17_INLINE constexpr error_type error_escape(_S_error_escape); /** The expression contained an invalid back reference. */ - constexpr error_type error_backref(_S_error_backref); + _GLIBCXX17_INLINE constexpr error_type error_backref(_S_error_backref); /** The expression contained mismatched [ and ]. */ - constexpr error_type error_brack(_S_error_brack); + _GLIBCXX17_INLINE constexpr error_type error_brack(_S_error_brack); /** The expression contained mismatched ( and ). */ - constexpr error_type error_paren(_S_error_paren); + _GLIBCXX17_INLINE constexpr error_type error_paren(_S_error_paren); /** The expression contained mismatched { and } */ - constexpr error_type error_brace(_S_error_brace); + _GLIBCXX17_INLINE constexpr error_type error_brace(_S_error_brace); /** The expression contained an invalid range in a {} expression. */ - constexpr error_type error_badbrace(_S_error_badbrace); + _GLIBCXX17_INLINE constexpr error_type error_badbrace(_S_error_badbrace); /** * The expression contained an invalid character range, * such as [b-a] in most encodings. */ - constexpr error_type error_range(_S_error_range); + _GLIBCXX17_INLINE constexpr error_type error_range(_S_error_range); /** * There was insufficient memory to convert the expression into a * finite state machine. */ - constexpr error_type error_space(_S_error_space); + _GLIBCXX17_INLINE constexpr error_type error_space(_S_error_space); /** * One of *?+{ was not preceded by a valid regular expression. */ - constexpr error_type error_badrepeat(_S_error_badrepeat); + _GLIBCXX17_INLINE constexpr error_type error_badrepeat(_S_error_badrepeat); /** * The complexity of an attempted match against a regular expression * exceeded a pre-set level. */ - constexpr error_type error_complexity(_S_error_complexity); + _GLIBCXX17_INLINE constexpr error_type error_complexity(_S_error_complexity); /** * There was insufficient memory to determine whether the * regular expression could match the specified character sequence. */ - constexpr error_type error_stack(_S_error_stack); + _GLIBCXX17_INLINE constexpr error_type error_stack(_S_error_stack); ///@} } // namespace regex_constants diff --git a/libstdc++-v3/include/ext/concurrence.h b/libstdc++-v3/include/ext/concurrence.h index aea861b534f..7fd81490eff 100644 --- a/libstdc++-v3/include/ext/concurrence.h +++ b/libstdc++-v3/include/ext/concurrence.h @@ -50,7 +50,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Compile time constant that indicates prefered locking policy in // the current configuration. - static const _Lock_policy __default_lock_policy = + _GLIBCXX17_INLINE const _Lock_policy __default_lock_policy = #ifndef __GTHREADS _S_single; #elif defined _GLIBCXX_HAVE_ATOMIC_LOCK_POLICY diff --git a/libstdc++-v3/include/pstl/execution_defs.h b/libstdc++-v3/include/pstl/execution_defs.h index 13b002931e8..3eca558dac2 100644 --- a/libstdc++-v3/include/pstl/execution_defs.h +++ b/libstdc++-v3/include/pstl/execution_defs.h @@ -107,10 +107,10 @@ class unsequenced_policy }; // 2.8, Execution policy objects -constexpr sequenced_policy seq{}; -constexpr parallel_policy par{}; -constexpr parallel_unsequenced_policy par_unseq{}; -constexpr unsequenced_policy unseq{}; +_GLIBCXX17_INLINE constexpr sequenced_policy seq{}; +_GLIBCXX17_INLINE constexpr parallel_policy par{}; +_GLIBCXX17_INLINE constexpr parallel_unsequenced_policy par_unseq{}; +_GLIBCXX17_INLINE constexpr unsequenced_policy unseq{}; // 2.3, Execution policy type trait template