From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id AF8E73858D33 for ; Wed, 1 Mar 2023 21:26:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AF8E73858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677706000; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wyTHx0cfQT8Z15g7Ep/lvL7273WoxkP+/BlUbtaErHQ=; b=GIjCRaLLN/A6DbstKK2Ry9sddSDPQDGrCJogb0LdXs0hJMjaeY+priPDUGFZCrM0wCO0Dc BiH5+zvN+jGvH77+kQYMOEZkNeqBiUD2ia37QKEevjwlfuJhTMWOii3mkOw+QmvLe0YA8E hYm7usa2XB/5cdypHR9WNG8LSKFUl/c= 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-519-4oS2Cf0OOpeVUpMrVwz9Ng-1; Wed, 01 Mar 2023 16:26:38 -0500 X-MC-Unique: 4oS2Cf0OOpeVUpMrVwz9Ng-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1D99D885621; Wed, 1 Mar 2023 21:26:38 +0000 (UTC) Received: from localhost (unknown [10.33.36.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA7AB2026D4B; Wed, 1 Mar 2023 21:26:37 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Make std::chrono::current_zone() default to UTC Date: Wed, 1 Mar 2023 21:26:37 +0000 Message-Id: <20230301212637.1481240-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tested x86_64-linux and powerpc-aix. Pushed to trunk. -- >8 -- This is consistent with the behaviour of glibc, which assumes UTC when /etc/localtime and TZ do not identify a valid time zone. The fallback tzdb used when no valid tzdata exists always contains the UTC zone, so this change means we have a valid tzdb and valid current zone even in the degenerate case. With this default we no longer need the AIX-specific kluge to try and identify TZ values specifying a 0-offset zone. We can just use the UTC default for those, as it has the same effect. It's still possible for chrono::current_zone() to fail, because the user could have provided a custom tzdata.zi file which doesn't contain the UTC time zone, so the "UTC" default would fail to find a valid zone, and throw an exception. That's just user error, they should not provide bad data and expect reasonable behaviour. libstdc++-v3/ChangeLog: * src/c++20/tzdb.cc (chrono::tzdb::current_zone()) Use "UTC" if current time zone cannot be determined. * testsuite/std/time/tzdb/1.cc: Remove conditions based on HAVE_TZDB macro and test all members unconditionally. --- libstdc++-v3/src/c++20/tzdb.cc | 15 ++++++--------- libstdc++-v3/testsuite/std/time/tzdb/1.cc | 22 +++++++++++----------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/libstdc++-v3/src/c++20/tzdb.cc b/libstdc++-v3/src/c++20/tzdb.cc index 2e7e173f0ef..2b68888e3b9 100644 --- a/libstdc++-v3/src/c++20/tzdb.cc +++ b/libstdc++-v3/src/c++20/tzdb.cc @@ -1692,19 +1692,16 @@ namespace std::chrono // https://www.ibm.com/support/pages/managing-time-zone-variable-posix if (const char* env = std::getenv("TZ")) { - string_view s(env); - if (s == "GMT0") - s = "Etc/GMT"; - else if (s.size() == 4 && s[3] == '0') - s = "Etc/UTC"; - - // This will fail unless TZ contains an IANA time zone name, - // or one of the special cases above. - if (auto tz = do_locate_zone(this->zones, this->links, s)) + // This will fail unless TZ contains an IANA time zone name. + if (auto tz = do_locate_zone(this->zones, this->links, env)) return tz; } #endif + // Default to UTC. + if (auto tz = do_locate_zone(this->zones, this->links, "UTC")) + return tz; + __throw_runtime_error("tzdb: cannot determine current zone"); } diff --git a/libstdc++-v3/testsuite/std/time/tzdb/1.cc b/libstdc++-v3/testsuite/std/time/tzdb/1.cc index 64e42701d3b..877a55b8d31 100644 --- a/libstdc++-v3/testsuite/std/time/tzdb/1.cc +++ b/libstdc++-v3/testsuite/std/time/tzdb/1.cc @@ -1,7 +1,6 @@ // { dg-options "-std=gnu++20" } // { dg-do run { target c++20 } } // { dg-require-effective-target cxx11_abi } -// { dg-additional-options "-DHAVE_TZDB" { target tzdb } } #include #include @@ -14,22 +13,25 @@ test_version() const tzdb& db = get_tzdb(); VERIFY( &db == &get_tzdb_list().front() ); -#ifdef HAVE_TZDB - VERIFY( db.version == remote_version() ); - const tzdb& reloaded = reload_tzdb(); - if (reloaded.version == db.version) - VERIFY( &reloaded == &db ); -#endif + const char* func; + try { + func = "remote_version"; + VERIFY( db.version == remote_version() ); + func = "reload_tzdb"; + const tzdb& reloaded = reload_tzdb(); + if (reloaded.version == db.version) + VERIFY( &reloaded == &db ); + } catch (const std::exception&) { + std::printf("std::chrono::%s() failed\n", func); + } } void test_current() { -#ifdef HAVE_TZDB const tzdb& db = get_tzdb(); const time_zone* tz = db.current_zone(); VERIFY( tz == std::chrono::current_zone() ); -#endif } void @@ -43,9 +45,7 @@ test_locate() VERIFY( tz == db.locate_zone("Etc/GMT") ); VERIFY( tz == db.locate_zone("Etc/GMT+0") ); -#ifdef HAVE_TZDB VERIFY( db.locate_zone(db.current_zone()->name()) == db.current_zone() ); -#endif } int main() -- 2.39.2