From: Jonathan Wakely <jwakely@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: Richard Biener <rguenther@suse.de>, Jakub Jelinek <jakub@redhat.com>
Subject: [PATCH] gcc: Add deleted assignment operators to non-copyable types
Date: Fri, 10 Mar 2023 15:35:13 +0000 [thread overview]
Message-ID: <20230310153513.2330396-1-jwakely@redhat.com> (raw)
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
next reply other threads:[~2023-03-10 15:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-10 15:35 Jonathan Wakely [this message]
2023-03-10 15:43 ` Richard Biener
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230310153513.2330396-1-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=rguenther@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).