From patchwork Wed Aug 24 13:05:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 731 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1410027wro; Wed, 24 Aug 2022 06:06:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR4+gApz2JatbQUyy+fqNUbVqM2KpqG+/4B2M4bPrCEI/60b17fiv54kZ7rO6knv7AZWNQPT X-Received: by 2002:aa7:c790:0:b0:443:a086:6877 with SMTP id n16-20020aa7c790000000b00443a0866877mr7526620eds.84.1661346396479; Wed, 24 Aug 2022 06:06:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661346396; cv=none; d=google.com; s=arc-20160816; b=eUHEbNmvuZNfLF8oZRzuszg2vKIdFwdFwIsPIcRSqTtfTidQP67pwyNdp5DPdRh9fG Cri7FH9p8vXT/Intf0rt28c/tJVtw/6RqoAY/gi+offMuvSqrk2FJk4g/4eNd8nL53xb 3AlawH+uzbBb5Y6dUJphUjKTfxi49XyhxWhEtSDv6WB66By7j4Df6mADIl9sdsHqk1U9 VF7tqJ4ogP3F7Nn3MDfF2UY5KpY4wiJIFGwjTto4jAJxleV5NNQcIFAydMTIzcnGnwTy 0s8ZDsMc8Kehu3gVxQBmyYWAL0s/CnU2OUwqu3QBtMVY4oRVI8ut/tTVYf5Kw1deyBRV xp5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=I9+VwmRI+l/wpoqiFXQqjnLNnkPMLa0A1dZvf5NqoIw=; b=0QoyqAP3rGMupQSX2lt4EhR1rhK12eGmsRDuBEM+2W1vMJQ90fhwlRdC1KrRBrW2Nx wZ5M+uNCLpDxcbJ+gP6QAZuNeFQWS9v8f9gx2oSGYTvb7OmRz2D/3wgpEPXkkgbWEr5v PxkBO3Ior2d7Az7PzopeeDiZIYZZ3sI/JEAcUeIVTLHacDGDd03zBFS5BqXXokAdYACK A7BN/+y6XhPXoAoyr36fGok+0U+B5VFmIAzsZaNjpJPVhrBGtjlNj9+7cTYgZMBH3V7q MVLB3lQ82Y2gl6Z4tbhEewP+vIc4bh4FfwndpsDVPK71cnHfZmr0D6lRmqhlysgaELur R1aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="soam//Es"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id v14-20020a056402348e00b0043d68d2cf50si5008934edc.77.2022.08.24.06.06.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 06:06:36 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="soam//Es"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 CC6D4385C401 for ; Wed, 24 Aug 2022 13:06:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC6D4385C401 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661346377; bh=I9+VwmRI+l/wpoqiFXQqjnLNnkPMLa0A1dZvf5NqoIw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=soam//EsrkkWZBZpQjrmwrs65Mxeh0VqbUkgRqJy69im5I+nqMFwgLXvD5i+qbCfW FBppnDtlzTXzmsdQKdbWtR0jLHvTh74MUwpVL8ENneCb3/Na2+09kuN4YGbWBwWE0N n9RY1Sx1DozHWIcxTqA5sbtjYUSwL67rqiLROc5Y= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 7032D3858C33 for ; Wed, 24 Aug 2022 13:05:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7032D3858C33 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-153-8Qh0ImhlORWJ_hxMcDiVyQ-1; Wed, 24 Aug 2022 09:05:32 -0400 X-MC-Unique: 8Qh0ImhlORWJ_hxMcDiVyQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 80B3780231E; Wed, 24 Aug 2022 13:05:32 +0000 (UTC) Received: from localhost (unknown [10.33.36.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A8892166B26; Wed, 24 Aug 2022 13:05:32 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add check for LWG 3741 problem case Date: Wed, 24 Aug 2022 14:05:31 +0100 Message-Id: <20220824130531.77910-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.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_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely 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?1742047958756035710?= X-GMAIL-MSGID: =?utf-8?q?1742047958756035710?= Tested powerpc64le-linux, pushed to trunk. -- >8 -- This LWG issue was closed as NAD, as it was just a bug in an implementation, not a defect in the standard. Libstdc++ never had that bug and always worked for the problem case. Add a test to ensure we don't regress. The problem occurs when abs is implemented using a ternary expression: return d >= d.zero() ? d : -d; If decltype(-d) is not the same as decltype(d) then this is ambiguous, because each type can be converted to the other, so there is no common type. libstdc++-v3/ChangeLog: * testsuite/20_util/duration_cast/rounding.cc: Check abs with non-reduced duration. --- libstdc++-v3/testsuite/20_util/duration_cast/rounding.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libstdc++-v3/testsuite/20_util/duration_cast/rounding.cc b/libstdc++-v3/testsuite/20_util/duration_cast/rounding.cc index af6e72d9e2e..c5179b6eb6e 100644 --- a/libstdc++-v3/testsuite/20_util/duration_cast/rounding.cc +++ b/libstdc++-v3/testsuite/20_util/duration_cast/rounding.cc @@ -58,3 +58,8 @@ static_assert( std::chrono::round(2501ms) == 3s ); static_assert( std::chrono::abs(100ms) == 100ms ); static_assert( std::chrono::abs(-100ms) == 100ms ); + +// LWG 3741. std::chrono::abs(duration) is ill-formed with non-reduced periods +using D1000 = std::chrono::duration>; +static_assert( std::chrono::abs(D1000(-2)) == D1000(2) ); +static_assert( std::is_same_v );