> 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 >
Re: [PATCH] gcc: Add deleted assignment operators to non-copyable types
Richard Biener via Gcc-patches Fri, 10 Mar 2023 07:44:25 -0800
- [PATCH] gcc: Add deleted assignment operat... Jonathan Wakely via Gcc-patches
- Re: [PATCH] gcc: Add deleted assignme... Richard Biener via Gcc-patches