Bug2442 residual: Review AudacityException classes...

... Have copy constructors only (no moves); disallow all assignments
This commit is contained in:
Paul Licameli 2020-06-05 13:43:10 -04:00
parent 13ec3300a9
commit 4a56af43aa
6 changed files with 18 additions and 50 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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;

View File

@ -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<InconsistencyException> 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);
}

View File

@ -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;

View File

@ -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: