* [PATCH] gcc: Add deleted assignment operators to non-copyable types
@ 2023-03-10 15:35 Jonathan Wakely
2023-03-10 15:43 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Wakely @ 2023-03-10 15:35 UTC (permalink / raw)
To: gcc-patches; +Cc: Richard Biener, Jakub Jelinek
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] gcc: Add deleted assignment operators to non-copyable types
2023-03-10 15:35 [PATCH] gcc: Add deleted assignment operators to non-copyable types Jonathan Wakely
@ 2023-03-10 15:43 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-03-10 15:43 UTC (permalink / raw)
To: Jonathan Wakely via Gcc-patches; +Cc: Jakub Jelinek
> 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
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-10 15:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-10 15:35 [PATCH] gcc: Add deleted assignment operators to non-copyable types Jonathan Wakely
2023-03-10 15:43 ` Richard Biener
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).