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.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 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=1678462521; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YkaIR7TcgFRNLQ8eAn708EdlOqyUzkKGb597F+ijh/4=; b=ZE0dwfKbMeFNO6Bq5XpJjuPHT8hPhPpGrQIp5GdlbYgGZ9zjie9yywLwq7Ff1qYnYcY8PX NvvYUjcHgI1cuj+/mlKsNILkyA28WC77HNTSdmINU7CYo41VPL40VmOZRVnkUUhK0P0962 HCsBI/nFZDAMcBM5f9Q8bhxb0fzlhT8= 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) From: Jonathan Wakely 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 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: 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() -- 2.39.2