From patchwork Fri Mar 10 15:35:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 67425 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp939988wrd; Fri, 10 Mar 2023 07:36:14 -0800 (PST) X-Google-Smtp-Source: AK7set/ghorCpwUVNgJPSdVf+Iy7gMJQjTyLjeE0lT2l3YGWndc8xr5koy8YUXcKpuifYR1f9XEI X-Received: by 2002:a17:907:c68a:b0:8de:acd1:90f6 with SMTP id ue10-20020a170907c68a00b008deacd190f6mr29474602ejc.4.1678462574235; Fri, 10 Mar 2023 07:36:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678462574; cv=none; d=google.com; s=arc-20160816; b=Ab5VklvkI4tXHuNSKmSWI4qoIa4hZSsfpsuuu4QWbrizE2ju4lTTA7Lf8/JD12WLOT ei9Dm3ekmgzka56IMP+gZXWQ+Eg6MsypJ7GS83Je3w6BluCdui2eNY1hWyk8FDc8g8PD wrZ26U3M6nQLop+Yx5McEahRWshmjEh7zWidNPKWm4u/IvwFH+eNzg7tfuns0rNhnu0U lo1RuClobLtIsVsdbR8emYREwp/iTWTsNN5g/22AYHT8CxFWtW6tbxYwijbymZO9QrcQ y873lXwdJV68hQQ0o9R59bkSO1jQ8aoxF+H0Sw3Ra+hmlxiyBpmOZ45C1xqOTNTzjm49 NhVQ== 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:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=YkaIR7TcgFRNLQ8eAn708EdlOqyUzkKGb597F+ijh/4=; b=KlpigeLM3rANheDnaqOZyqgGYQC/cjQoR1WhC5+ib1C+8V2JnFXssZZXwaM2msko64 zZdJDr4Y0Xqq8D1DjLL1Xv9H4TUvKqR+O4x4et6wlTuvZHURRjlGtLRZc/jaUTKVpkZw VjrmUi+EK0SCErFnnnSIBZux5zt9FCLMPEFSfJ6/oKJDTOG2R54JriDg9hdDhf3Dpg7q PitaNOfhSy+A6u7mZXWE//pd6rMj69lI7dntozYvvrdR1d8XslppGKjyKUxuytxT0V5D hEemz0dctFeJ9VRoOA/DdwWtsHMCjg8FObBP2eWdOqTArXTrVXzK018l9e6Dimps2AaZ 6TDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GVkW29yP; 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 ga22-20020a1709070c1600b008d6b51de6bcsi113539ejc.32.2023.03.10.07.36.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Mar 2023 07:36:14 -0800 (PST) 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=GVkW29yP; 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 312653858410 for ; Fri, 10 Mar 2023 15:36:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 312653858410 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678462565; bh=YkaIR7TcgFRNLQ8eAn708EdlOqyUzkKGb597F+ijh/4=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=GVkW29yPzhz+TYS+C9ozU546B1rXeddcz0LpDSqgAWXqKWyRAExqevrlCRpZ4NsS3 aks6yc3EK8IAWCEpaF426giAb74KIecqp1Tb1JEwUNopAVD2yN3elKDo9m80GmKnYX bxOC5FWpaXGifG3AnmV/LJukI4T6rpkhiYTG0v+Q= 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 5C0E7385842B for ; Fri, 10 Mar 2023 15:35:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C0E7385842B 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-156-1rI1kKmjOoi-loIif-oiPw-1; Fri, 10 Mar 2023 10:35:14 -0500 X-MC-Unique: 1rI1kKmjOoi-loIif-oiPw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4A1B7811E6E; Fri, 10 Mar 2023 15:35:14 +0000 (UTC) Received: from localhost (unknown [10.33.36.96]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16D7A492B04; Fri, 10 Mar 2023 15:35:13 +0000 (UTC) To: gcc-patches@gcc.gnu.org Cc: Richard Biener , Jakub Jelinek Subject: [PATCH] gcc: Add deleted assignment operators to non-copyable types Date: Fri, 10 Mar 2023 15:35:13 +0000 Message-Id: <20230310153513.2330396-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 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?1759995572486752359?= X-GMAIL-MSGID: =?utf-8?q?1759995572486752359?= Bootstrapped and regtested on powerpc64le-linux. OK for trunk? It's safe to do now rather than waiting for Stage 1, because if we were actually relying on copy-assigning these types it would have failed to compile with this change. So it has no functional change, but will help prevent any future misuse of these types. -- >8 -- The auto_timevar and auto_cond_timevar classes are supposed to be non-copyable, but they have implicit assignment operators. Define their assignment operators as deleted. The auto_bitmap declares private copy/move constructors/assignments, which can be replced with deleted copies to get the same effect but using more idiomatic C++11 style. gcc/ChangeLog: * bitmap.h (class auto_bitmap): Replace private-and-undefined copy and move special member functions with deleted copies. * timevar.h (class auto_timevar): Delete assignment operator. (class auto_cond_timevar): Likewise. --- gcc/bitmap.h | 11 ++++------- gcc/timevar.h | 6 ++++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/gcc/bitmap.h b/gcc/bitmap.h index 43337d2e9d9..ccb484651ab 100644 --- a/gcc/bitmap.h +++ b/gcc/bitmap.h @@ -945,7 +945,7 @@ bmp_iter_and_compl (bitmap_iterator *bi, unsigned *bit_no) /* A class that ties the lifetime of a bitmap to its scope. */ class auto_bitmap { - public: +public: auto_bitmap (ALONE_CXX_MEM_STAT_INFO) { bitmap_initialize (&m_bits, &bitmap_default_obstack PASS_MEM_STAT); } explicit auto_bitmap (bitmap_obstack *o CXX_MEM_STAT_INFO) @@ -954,12 +954,9 @@ class auto_bitmap // Allow calling bitmap functions on our bitmap. operator bitmap () { return &m_bits; } - private: - // Prevent making a copy that references our bitmap. - auto_bitmap (const auto_bitmap &); - auto_bitmap &operator = (const auto_bitmap &); - auto_bitmap (auto_bitmap &&); - auto_bitmap &operator = (auto_bitmap &&); + // Prevent shallow copies. + auto_bitmap (const auto_bitmap &) = delete; + auto_bitmap &operator = (const auto_bitmap &) = delete; bitmap_head m_bits; }; diff --git a/gcc/timevar.h b/gcc/timevar.h index ad465731609..b2d13d44190 100644 --- a/gcc/timevar.h +++ b/gcc/timevar.h @@ -247,8 +247,9 @@ class auto_timevar m_timer->pop (m_tv); } - // Disallow copies. + // Prevent shallow copies. auto_timevar (const auto_timevar &) = delete; + auto_timevar &operator= (const auto_timevar &) = delete; private: timer *m_timer; @@ -279,8 +280,9 @@ class auto_cond_timevar m_timer->cond_stop (m_tv); } - // Disallow copies. + // Prevent shallow copies. auto_cond_timevar (const auto_cond_timevar &) = delete; + auto_cond_timevar &operator= (const auto_cond_timevar &) = delete; private: void start()