From: Richard Biener <rguenther@suse.de>
To: Jonathan Wakely via Gcc-patches <gcc-patches@gcc.gnu.org>
Cc: Jakub Jelinek <jakub@redhat.com>
Subject: Re: [PATCH] gcc: Add deleted assignment operators to non-copyable types
Date: Fri, 10 Mar 2023 16:43:59 +0100 [thread overview]
Message-ID: <A039C91D-BB90-4D3B-A14A-15B490F86816@suse.de> (raw)
In-Reply-To: <20230310153513.2330396-1-jwakely@redhat.com>
> Am 10.03.2023 um 16:36 schrieb Jonathan Wakely via Gcc-patches <gcc-patches@gcc.gnu.org>:
>
> Bootstrapped and regtested on powerpc64le-linux.
>
> OK for trunk?
Ok.
Thanks,
Richard
> 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
>
prev parent reply other threads:[~2023-03-10 15:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-10 15:35 Jonathan Wakely
2023-03-10 15:43 ` Richard Biener [this message]
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=A039C91D-BB90-4D3B-A14A-15B490F86816@suse.de \
--to=rguenther@suse.de \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
/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).