From 4a56af43aa4833ba6f6ee96911797170cebf3dd6 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Fri, 5 Jun 2020 13:43:10 -0400 Subject: [PATCH] Bug2442 residual: Review AudacityException classes... ... Have copy constructors only (no moves); disallow all assignments --- src/AudacityException.cpp | 15 --------------- src/AudacityException.h | 11 +++++++---- src/InconsistencyException.h | 10 ---------- src/Sequence.cpp | 23 +++++++++++------------ src/UserException.h | 6 ------ src/blockfile/NotYetAvailableException.h | 3 --- 6 files changed, 18 insertions(+), 50 deletions(-) diff --git a/src/AudacityException.cpp b/src/AudacityException.cpp index f4d5dc381..1801a7cf1 100644 --- a/src/AudacityException.cpp +++ b/src/AudacityException.cpp @@ -53,21 +53,6 @@ MessageBoxException::MessageBoxException( const MessageBoxException& that ) that.moved = true; } -MessageBoxException &MessageBoxException::operator = ( MessageBoxException &&that ) -{ - caption = that.caption; - if ( this != &that ) { - AudacityException::operator=( std::move(that) ); - if (!moved) - wxAtomicDec( sOutstandingMessages ); - - moved = that.moved; - that.moved = true; - } - - return *this; -} - MessageBoxException::~MessageBoxException() { if (!moved) diff --git a/src/AudacityException.h b/src/AudacityException.h index eb70bc7ac..eca1f49b5 100644 --- a/src/AudacityException.h +++ b/src/AudacityException.h @@ -33,10 +33,14 @@ public: protected: // Make this protected to prevent slicing copies - AudacityException( AudacityException&& ) {} AudacityException( const AudacityException& ) = default; - AudacityException &operator = (AudacityException &&) { return *this;} - AudacityException &operator = ( const AudacityException & ) PROHIBITED; + + // Don't allow moves of this class or subclasses + // see https://bugzilla.audacityteam.org/show_bug.cgi?id=2442 + AudacityException( AudacityException&& ) = delete; + + // Disallow assignment + AudacityException &operator = ( const AudacityException & ) = delete; }; /// \brief A subclass of AudacityException whose delayed handler action displays @@ -56,7 +60,6 @@ protected: ~MessageBoxException() override; MessageBoxException( const MessageBoxException& ); - MessageBoxException &operator = ( MessageBoxException && ); // Format a default error message for this exception. virtual TranslatableString ErrorMessage() const = 0; diff --git a/src/InconsistencyException.h b/src/InconsistencyException.h index ef4a47d4b..81664aa4e 100644 --- a/src/InconsistencyException.h +++ b/src/InconsistencyException.h @@ -32,16 +32,6 @@ public: , file{ that.file } , line{ that.line } {} - InconsistencyException &operator = (InconsistencyException &&that) - { - if (this != &that) { - MessageBoxException::operator= (std::move(that)); - func = that.func; - file = that.file; - line = that.line; - } - return *this; - } ~InconsistencyException() override; diff --git a/src/Sequence.cpp b/src/Sequence.cpp index a285d1b69..b1352a6b9 100644 --- a/src/Sequence.cpp +++ b/src/Sequence.cpp @@ -1835,39 +1835,38 @@ void Sequence::ConsistencyCheck sampleCount mNumSamples, const wxChar *whereStr, bool WXUNUSED(mayThrow)) { - bool bError = false; // Construction of the exception at the appropriate line of the function // gives a little more discrimination - InconsistencyException ex; + Optional ex; unsigned int numBlocks = mBlock.size(); unsigned int i; sampleCount pos = from < numBlocks ? mBlock[from].start : mNumSamples; if ( from == 0 && pos != 0 ) - ex = CONSTRUCT_INCONSISTENCY_EXCEPTION, bError = true; + ex.emplace( CONSTRUCT_INCONSISTENCY_EXCEPTION ); - for (i = from; !bError && i < numBlocks; i++) { + for (i = from; !ex && i < numBlocks; i++) { const SeqBlock &seqBlock = mBlock[i]; if (pos != seqBlock.start) - ex = CONSTRUCT_INCONSISTENCY_EXCEPTION, bError = true; + ex.emplace( CONSTRUCT_INCONSISTENCY_EXCEPTION ); if ( seqBlock.f ) { const auto length = seqBlock.f->GetLength(); if (length > maxSamples) - ex = CONSTRUCT_INCONSISTENCY_EXCEPTION, bError = true; + ex.emplace( CONSTRUCT_INCONSISTENCY_EXCEPTION ); pos += length; } else - ex = CONSTRUCT_INCONSISTENCY_EXCEPTION, bError = true; + ex.emplace( CONSTRUCT_INCONSISTENCY_EXCEPTION ); } - if ( !bError && pos != mNumSamples ) - ex = CONSTRUCT_INCONSISTENCY_EXCEPTION, bError = true; + if ( !ex && pos != mNumSamples ) + ex.emplace( CONSTRUCT_INCONSISTENCY_EXCEPTION ); - if ( bError ) + if ( ex ) { wxLogError(wxT("*** Consistency check failed at %d after %s. ***"), - ex.GetLine(), whereStr); + ex->GetLine(), whereStr); wxString str; DebugPrintf(mBlock, mNumSamples, &str); wxLogError(wxT("%s"), str); @@ -1876,7 +1875,7 @@ void Sequence::ConsistencyCheck wxT("Undo the failed operation(s), then export or save your work and quit.")); //if (mayThrow) - //throw ex; + //throw *ex; //else wxASSERT(false); } diff --git a/src/UserException.h b/src/UserException.h index da0fd7e94..ad90b0e92 100644 --- a/src/UserException.h +++ b/src/UserException.h @@ -21,12 +21,6 @@ class UserException final : public AudacityException public: UserException() {} - UserException(UserException &&that) - : AudacityException{ std::move( that ) } - {} - - UserException& operator= (UserException&&) PROHIBITED; - ~UserException() override; void DelayedHandlerAction() override; diff --git a/src/blockfile/NotYetAvailableException.h b/src/blockfile/NotYetAvailableException.h index dd89bdd07..536b1a963 100644 --- a/src/blockfile/NotYetAvailableException.h +++ b/src/blockfile/NotYetAvailableException.h @@ -18,9 +18,6 @@ class NotYetAvailableException final : public FileException public: NotYetAvailableException( const wxFileName &fileName ) : FileException{ Cause::Read, fileName } {} - NotYetAvailableException(NotYetAvailableException &&that) - : FileException( std::move( that ) ) {} - NotYetAvailableException& operator= (NotYetAvailableException&&) PROHIBITED; ~NotYetAvailableException(); protected: