Bug2442 residual: Review AudacityException classes...
... Have copy constructors only (no moves); disallow all assignments
This commit is contained in:
parent
13ec3300a9
commit
4a56af43aa
|
@ -53,21 +53,6 @@ MessageBoxException::MessageBoxException( const MessageBoxException& that )
|
||||||
that.moved = true;
|
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()
|
MessageBoxException::~MessageBoxException()
|
||||||
{
|
{
|
||||||
if (!moved)
|
if (!moved)
|
||||||
|
|
|
@ -33,10 +33,14 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Make this protected to prevent slicing copies
|
// Make this protected to prevent slicing copies
|
||||||
AudacityException( AudacityException&& ) {}
|
|
||||||
AudacityException( const AudacityException& ) = default;
|
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
|
/// \brief A subclass of AudacityException whose delayed handler action displays
|
||||||
|
@ -56,7 +60,6 @@ protected:
|
||||||
~MessageBoxException() override;
|
~MessageBoxException() override;
|
||||||
|
|
||||||
MessageBoxException( const MessageBoxException& );
|
MessageBoxException( const MessageBoxException& );
|
||||||
MessageBoxException &operator = ( MessageBoxException && );
|
|
||||||
|
|
||||||
// Format a default error message for this exception.
|
// Format a default error message for this exception.
|
||||||
virtual TranslatableString ErrorMessage() const = 0;
|
virtual TranslatableString ErrorMessage() const = 0;
|
||||||
|
|
|
@ -32,16 +32,6 @@ public:
|
||||||
, file{ that.file }
|
, file{ that.file }
|
||||||
, line{ that.line }
|
, 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;
|
~InconsistencyException() override;
|
||||||
|
|
||||||
|
|
|
@ -1835,39 +1835,38 @@ void Sequence::ConsistencyCheck
|
||||||
sampleCount mNumSamples, const wxChar *whereStr,
|
sampleCount mNumSamples, const wxChar *whereStr,
|
||||||
bool WXUNUSED(mayThrow))
|
bool WXUNUSED(mayThrow))
|
||||||
{
|
{
|
||||||
bool bError = false;
|
|
||||||
// Construction of the exception at the appropriate line of the function
|
// Construction of the exception at the appropriate line of the function
|
||||||
// gives a little more discrimination
|
// gives a little more discrimination
|
||||||
InconsistencyException ex;
|
Optional<InconsistencyException> ex;
|
||||||
|
|
||||||
unsigned int numBlocks = mBlock.size();
|
unsigned int numBlocks = mBlock.size();
|
||||||
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
sampleCount pos = from < numBlocks ? mBlock[from].start : mNumSamples;
|
sampleCount pos = from < numBlocks ? mBlock[from].start : mNumSamples;
|
||||||
if ( from == 0 && pos != 0 )
|
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];
|
const SeqBlock &seqBlock = mBlock[i];
|
||||||
if (pos != seqBlock.start)
|
if (pos != seqBlock.start)
|
||||||
ex = CONSTRUCT_INCONSISTENCY_EXCEPTION, bError = true;
|
ex.emplace( CONSTRUCT_INCONSISTENCY_EXCEPTION );
|
||||||
|
|
||||||
if ( seqBlock.f ) {
|
if ( seqBlock.f ) {
|
||||||
const auto length = seqBlock.f->GetLength();
|
const auto length = seqBlock.f->GetLength();
|
||||||
if (length > maxSamples)
|
if (length > maxSamples)
|
||||||
ex = CONSTRUCT_INCONSISTENCY_EXCEPTION, bError = true;
|
ex.emplace( CONSTRUCT_INCONSISTENCY_EXCEPTION );
|
||||||
pos += length;
|
pos += length;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ex = CONSTRUCT_INCONSISTENCY_EXCEPTION, bError = true;
|
ex.emplace( CONSTRUCT_INCONSISTENCY_EXCEPTION );
|
||||||
}
|
}
|
||||||
if ( !bError && pos != mNumSamples )
|
if ( !ex && pos != mNumSamples )
|
||||||
ex = CONSTRUCT_INCONSISTENCY_EXCEPTION, bError = true;
|
ex.emplace( CONSTRUCT_INCONSISTENCY_EXCEPTION );
|
||||||
|
|
||||||
if ( bError )
|
if ( ex )
|
||||||
{
|
{
|
||||||
wxLogError(wxT("*** Consistency check failed at %d after %s. ***"),
|
wxLogError(wxT("*** Consistency check failed at %d after %s. ***"),
|
||||||
ex.GetLine(), whereStr);
|
ex->GetLine(), whereStr);
|
||||||
wxString str;
|
wxString str;
|
||||||
DebugPrintf(mBlock, mNumSamples, &str);
|
DebugPrintf(mBlock, mNumSamples, &str);
|
||||||
wxLogError(wxT("%s"), 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."));
|
wxT("Undo the failed operation(s), then export or save your work and quit."));
|
||||||
|
|
||||||
//if (mayThrow)
|
//if (mayThrow)
|
||||||
//throw ex;
|
//throw *ex;
|
||||||
//else
|
//else
|
||||||
wxASSERT(false);
|
wxASSERT(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,12 +21,6 @@ class UserException final : public AudacityException
|
||||||
public:
|
public:
|
||||||
UserException() {}
|
UserException() {}
|
||||||
|
|
||||||
UserException(UserException &&that)
|
|
||||||
: AudacityException{ std::move( that ) }
|
|
||||||
{}
|
|
||||||
|
|
||||||
UserException& operator= (UserException&&) PROHIBITED;
|
|
||||||
|
|
||||||
~UserException() override;
|
~UserException() override;
|
||||||
|
|
||||||
void DelayedHandlerAction() override;
|
void DelayedHandlerAction() override;
|
||||||
|
|
|
@ -18,9 +18,6 @@ class NotYetAvailableException final : public FileException
|
||||||
public:
|
public:
|
||||||
NotYetAvailableException( const wxFileName &fileName )
|
NotYetAvailableException( const wxFileName &fileName )
|
||||||
: FileException{ Cause::Read, fileName } {}
|
: FileException{ Cause::Read, fileName } {}
|
||||||
NotYetAvailableException(NotYetAvailableException &&that)
|
|
||||||
: FileException( std::move( that ) ) {}
|
|
||||||
NotYetAvailableException& operator= (NotYetAvailableException&&) PROHIBITED;
|
|
||||||
~NotYetAvailableException();
|
~NotYetAvailableException();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Reference in New Issue