Message ID | 20230314103040.2697873-1-jwakely@redhat.com |
---|---|
State | Committed |
Commit | 4d771291f70dab571e7c18f9f5f8af4f27737244 |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BBF22385B53B for <patchwork@sourceware.org>; Tue, 14 Mar 2023 10:31:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BBF22385B53B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678789896; bh=NHgbToarzuQhFrWE5cBe8tidFB8jZLQrR2MioTSRESU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=mhmvPeYilMNTYeleB1fO2JGtN7NsmU0hE3FE6VJ3TUgXHIVVVGaU2F5foPmfUt7uy kO8Lp9V7qr57bRWtTDVV4v34eIOjNHXgUtJJuGzWCMyKRoMWrbBvtPg51XdBOd2OYT /5mohM7VeHhZ+hnNnzk17wdsTG6+LCshZUHOl5aE= 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 857B9385B513 for <gcc-patches@gcc.gnu.org>; Tue, 14 Mar 2023 10:30:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 857B9385B513 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-654-DDNQyDQ1PgiODUwSni9_zg-1; Tue, 14 Mar 2023 06:30:41 -0400 X-MC-Unique: DDNQyDQ1PgiODUwSni9_zg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8772A885620; Tue, 14 Mar 2023 10:30:41 +0000 (UTC) Received: from localhost (unknown [10.33.36.255]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F8A6C158C2; Tue, 14 Mar 2023 10:30:41 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix preprocessor condition for inline variables Date: Tue, 14 Mar 2023 10:30:40 +0000 Message-Id: <20230314103040.2697873-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.8 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=unavailable 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <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>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Jonathan Wakely via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Jonathan Wakely <jwakely@redhat.com> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
[committed] libstdc++: Fix preprocessor condition for inline variables
|
|
Commit Message
Jonathan Wakely
March 14, 2023, 10:30 a.m. UTC
Tested x86_64-linux. Pushed to trunk. -- >8 -- Although variable templates are valid in C++14, inline ones aren't. These are only used in C++17 (or later) code, so they don't need to be defined for C++14. libstdc++-v3/ChangeLog: * include/bits/chrono.h (__is_duration_v, __is_time_point_v): Only define for C++17 and later. --- libstdc++-v3/include/bits/chrono.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
Am Di., 14. März 2023 um 11:32 Uhr schrieb Jonathan Wakely via Libstdc++ <libstdc++@gcc.gnu.org>: > > Tested x86_64-linux. Pushed to trunk. > > -- >8 -- > > Although variable templates are valid in C++14, inline ones aren't. > These are only used in C++17 (or later) code, so they don't need to be > defined for C++14. > > libstdc++-v3/ChangeLog: > > * include/bits/chrono.h (__is_duration_v, __is_time_point_v): > Only define for C++17 and later. > --- > libstdc++-v3/include/bits/chrono.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/libstdc++-v3/include/bits/chrono.h b/libstdc++-v3/include/bits/chrono.h > index b2e4f4c33a8..fb99fe5eed7 100644 > --- a/libstdc++-v3/include/bits/chrono.h > +++ b/libstdc++-v3/include/bits/chrono.h > @@ -244,7 +244,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > using __disable_if_is_duration > = typename enable_if<!__is_duration<_Tp>::value, _Tp>::type; > > -#if __cpp_variable_templates > +#if __cplusplus >= 201703L > template<typename _Tp> > inline constexpr bool __is_duration_v = false; > template<typename _Rep, typename _Period> > -- > 2.39.2 Apologies for the late response: What about changing the test to check for __cpp_inline_variables or combining it with __cpp_variable_templates instead? Thanks, - Daniel
On Tue, 14 Mar 2023 at 10:51, Daniel Krügler wrote: > Apologies for the late response: > > I only just committed the change, so it's not delayed :-) > What about changing the test to check for __cpp_inline_variables or > combining it with __cpp_variable_templates instead? > > We could do that, but it would complicate their use. Currently they're only used in C++17 code (chrono::floor etc.) and C++20 code (chrono::hh_mm_ss etc. and chrono formatters). We know it's OK for C++17 and C++20 code to use __is_duration_v and __is_time_point_v because they're defined for C++17 and later. If we change them to be defined for __cpp_inline_variables && __cpp_variable_templates then what changes? It should be safe to assume we can still use them in C++17 and C++20 code, but could we also use them elsewhere, e.g. in C++14 code such as chrono::literals? Maybe, but only if __cpp_inline_variables is defined for C++14 mode, and if it's not, then we'd need something like: #if __cplusplus >= 201402L template<typename _Dur> #if __cpp_inline_variables enable_if_t<__is_duration_v<_Dur>, _Dur> #else enable_if_t<__is_duration<_Dur>::value, _Dur> #endif foo(const _Dur&); #endif And this is not an improvement over simply: #if __cplusplus >= 201402L template<typename _Dur> enable_if_t<__is_duration<_Dur>::value, _Dur> foo(const _Dur&); #endif So I don't see why we would want to do it. I think it was a mistake for me to ever make them depend on __cpp_variable_templates, instead of just depending on C++17. I think it's better to fix that mistake.
Am Di., 14. März 2023 um 12:02 Uhr schrieb Jonathan Wakely <jwakely@redhat.com>: > > On Tue, 14 Mar 2023 at 10:51, Daniel Krügler wrote: >> >> Apologies for the late response: >> > > I only just committed the change, so it's not delayed :-) > > >> >> What about changing the test to check for __cpp_inline_variables or >> combining it with __cpp_variable_templates instead? >> > > We could do that, but it would complicate their use. > > Currently they're only used in C++17 code (chrono::floor etc.) and C++20 code (chrono::hh_mm_ss etc. and chrono formatters). We know it's OK for C++17 and C++20 code to use __is_duration_v and __is_time_point_v because they're defined for C++17 and later. > > If we change them to be defined for __cpp_inline_variables && __cpp_variable_templates then what changes? It should be safe to assume we can still use them in C++17 and C++20 code, but could we also use them elsewhere, e.g. in C++14 code such as chrono::literals? Maybe, but only if __cpp_inline_variables is defined for C++14 mode, and if it's not, then we'd need something like: > > #if __cplusplus >= 201402L > template<typename _Dur> > #if __cpp_inline_variables > enable_if_t<__is_duration_v<_Dur>, _Dur> > #else > enable_if_t<__is_duration<_Dur>::value, _Dur> > #endif > foo(const _Dur&); > #endif > > And this is not an improvement over simply: > > #if __cplusplus >= 201402L > template<typename _Dur> > enable_if_t<__is_duration<_Dur>::value, _Dur> > foo(const _Dur&); > #endif > > So I don't see why we would want to do it. I think it was a mistake for me to ever make them depend on __cpp_variable_templates, instead of just depending on C++17. I think it's better to fix that mistake. Sounds reasonable, thanks. - Daniel
diff --git a/libstdc++-v3/include/bits/chrono.h b/libstdc++-v3/include/bits/chrono.h index b2e4f4c33a8..fb99fe5eed7 100644 --- a/libstdc++-v3/include/bits/chrono.h +++ b/libstdc++-v3/include/bits/chrono.h @@ -244,7 +244,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using __disable_if_is_duration = typename enable_if<!__is_duration<_Tp>::value, _Tp>::type; -#if __cpp_variable_templates +#if __cplusplus >= 201703L template<typename _Tp> inline constexpr bool __is_duration_v = false; template<typename _Rep, typename _Period>