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: 66230 Return-Path: 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 301F13857C44 for ; Fri, 10 Mar 2023 15:35:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 301F13857C44 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678462549; 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=oK5vuhAkmZ4bA19FtWAILKg+KbLfIuVTWlj0SWTkVpgkASKPTmT6uvBSPVWQ1v8rE YbLlp3mpOb8rerCDEmyXMfvPKoWHGZg4WPEw7i86jg5+uMYjQniYs3rThV26Pb0FhM ays4p75fKxYL9Fe5h7euS+bUT0PxO3Nc4lgmHu6o= 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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()