From patchwork Mon Apr 24 16:23:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1773000 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=JRrqqpqa; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q4r8C2wXTz23s0 for ; Tue, 25 Apr 2023 02:25:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5FA203857732 for ; Mon, 24 Apr 2023 16:25:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5FA203857732 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682353513; bh=QUsFusgXvCMUs2VFXlnju0RuBAK/ohTZRRZbkW3NEcI=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=JRrqqpqaIEXnYQM7Q93VcDVcrokszoT4k+2jemTIZutVIKYO4iwAJZ7e7BNhYKjCJ Rfgu76s85hKWZUzQS4MrGUskaLXTNc6s+Q/FHz7VRsaxtqXMcaN2N8VtgAX/s6F/6b 3UAg+wWmn5u0CMIw20s8f1XjBxbdVc4I2jrsf1Pg= 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 9CD273858414 for ; Mon, 24 Apr 2023 16:23:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9CD273858414 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_256_GCM_SHA384) id us-mta-578-SDVaNgFcNQKzP_WaEiWz8A-1; Mon, 24 Apr 2023 12:23:53 -0400 X-MC-Unique: SDVaNgFcNQKzP_WaEiWz8A-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-5ef2585c1beso26130406d6.2 for ; Mon, 24 Apr 2023 09:23:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682353433; x=1684945433; 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=QUsFusgXvCMUs2VFXlnju0RuBAK/ohTZRRZbkW3NEcI=; b=EcU4ue2+NyBjetPQdd5wGKiTKch0rgdOB7OkhHRa8cGuXGsEtblf/kKk2xmCNtim3C HM+Wqzl3JUbdP0ZsS3RXgN+MgsTdcZ0l5xW/CKL9YoFnkJENLIbcSHRW5GRRXDp2rRHq QHckm54f91kvS6guVPQBNtyhp1d5G2P1R3uZn/hL8UI3vAu017xoVDvjh10ryMXeDyEY gE12tW/4bMtrxZKZwdjWpi7blUDB19DJcp/hMPJLsXqgnTH3Vfi7Ta07TYFRG9V6uv+p y8Nx/khKE+BlJU827gNUbh335iFwyXmGBhK2OdInf8ixSywl/aA6NXq2NBG1kxsOYMeJ igRQ== X-Gm-Message-State: AAQBX9eYlqqW2hBNfYQ4KGQ32Me3vJy6dyVPtiX1Xso1Yp6bRFpzpNBD oWlFyoML1vrctFg1t+7UixziOQ2v50A7fXehe125e+iL1SfbDWW6D8xUfazNXApBFKniXl8LuU8 XgrckiILq9neQJXGUT/GO1qJT2DGepAejgi+f1pGzwmjvd+ZGJzpfjJ1lROyuTrqk9sR9v6CB2b U= X-Received: by 2002:ac8:5ac6:0:b0:3ee:be98:9fe9 with SMTP id d6-20020ac85ac6000000b003eebe989fe9mr24101142qtd.3.1682353432896; Mon, 24 Apr 2023 09:23:52 -0700 (PDT) X-Google-Smtp-Source: AKy350Yg9Z8ga/YPju2MwQOGYM6+Z+c9IuaT9oTvuNX24AfNuoAjR3WUXwpZYTWgyMDn0UlqcHTQuQ== X-Received: by 2002:ac8:5ac6:0:b0:3ee:be98:9fe9 with SMTP id d6-20020ac85ac6000000b003eebe989fe9mr24101099qtd.3.1682353432551; Mon, 24 Apr 2023 09:23:52 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id 206-20020a3705d7000000b007469b5bc2c4sm3709087qkf.13.2023.04.24.09.23.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 09:23:52 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH] libstdc++: Make __max_size_type and __max_diff_type structural Date: Mon, 24 Apr 2023 12:23:47 -0400 Message-ID: <20230424162347.104093-1-ppalka@redhat.com> X-Mailer: git-send-email 2.40.0.374.g7580f92ffa MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.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, 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: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch makes these integer-class type structural types by changing their private data members into public ones, which allows them to be used as NTTP types. I'm not sure if this is required by the standard but it seems handy. Tested on x86_64-pc-linux-gnu, does this look OK for trunk? libstdc++-v3/ChangeLog: * include/bits/max_size_type.h (__max_size_type::_M_val): Make public instead of private. (__max_size_type::_M_msb): Likewise. (__max_diff_type::_M_rep): Likewise. * testsuite/std/ranges/iota/max_size_type.cc: Verify __max_diff_type and __max_size_type are structural. --- libstdc++-v3/include/bits/max_size_type.h | 4 ++-- libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/bits/max_size_type.h b/libstdc++-v3/include/bits/max_size_type.h index 4796135d073..d6705bbe4c8 100644 --- a/libstdc++-v3/include/bits/max_size_type.h +++ b/libstdc++-v3/include/bits/max_size_type.h @@ -423,10 +423,11 @@ namespace ranges using __rep = unsigned long long; #endif static constexpr size_t _S_rep_bits = sizeof(__rep) * __CHAR_BIT__; - private: + __rep _M_val = 0; unsigned _M_msb:1 = 0; + private: constexpr explicit __max_size_type(__rep __val, int __msb) noexcept : _M_val(__val), _M_msb(__msb) @@ -750,7 +751,6 @@ namespace ranges { return !(__l < __r); } #endif - private: __max_size_type _M_rep = 0; friend class __max_size_type; diff --git a/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc b/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc index 985acd5a803..9afd05d5acf 100644 --- a/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc +++ b/libstdc++-v3/testsuite/std/ranges/iota/max_size_type.cc @@ -400,6 +400,13 @@ static_assert(max_diff_t(max_size_t(1) << (numeric_limits::digits-1)) == numeric_limits::min()); +// Verify that the types are structural types and can therefore be used +// as NTTP types. +template struct Su { static_assert(V*V == V+132); }; +template struct Ss { static_assert(V*V == V+132); }; +template struct Su<12>; +template struct Ss<12>; + int main() {