From 9e5d31d347873f7e54f5a4b7e8528fa61490b792 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Fri, 19 Feb 2016 10:46:23 -0500 Subject: [PATCH] More changes to Audacity.h to hide new and delete from code sweeps... ... changed some comments, and hid = delete in a macro. That is a new C++11 feature that lets you stipulate that a class suppresses an otherwise inherited or generated name. --- src/AboutDialog.h | 4 ++-- src/Audacity.h | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/AboutDialog.h b/src/AboutDialog.h index 2f7a73c00..06aeb30a3 100644 --- a/src/AboutDialog.h +++ b/src/AboutDialog.h @@ -28,8 +28,8 @@ struct AboutDialogCreditItem { {} // No copy - AboutDialogCreditItem(const AboutDialogCreditItem&) = delete; - AboutDialogCreditItem& operator= (const AboutDialogCreditItem&) = delete; + AboutDialogCreditItem(const AboutDialogCreditItem&) PROHIBITED; + AboutDialogCreditItem& operator= (const AboutDialogCreditItem&) PROHIBITED; // Move constructor, because wxString lacks one AboutDialogCreditItem(AboutDialogCreditItem &&moveMe) diff --git a/src/Audacity.h b/src/Audacity.h index 84f993713..ade47f655 100644 --- a/src/Audacity.h +++ b/src/Audacity.h @@ -164,9 +164,12 @@ void QuitAudacity(); #include #include -// Reviewed, certified, non-leaky uses of new that immediately entrust their results to RAII objects. -// You may use it in new code when constructing a wxWindow subclass with non-NULL parent window. -// You may use it in new code when the new expression is the constructor argument for a standard smart +// This renames a good use of this C++ keyword that we don't need to review when hunting for leaks. +#define PROHIBITED = delete + +// Reviewed, certified, non-leaky uses of NEW that immediately entrust their results to RAII objects. +// You may use it in NEW code when constructing a wxWindow subclass with non-NULL parent window. +// You may use it in NEW code when the NEW expression is the constructor argument for a standard smart // pointer like std::unique_ptr or std::shared_ptr. #define safenew new @@ -181,8 +184,8 @@ void QuitAudacity(); auto q = std::make_unique(count); q[0].DoSomethingElse(); - The first hides naked new and delete from the source code. - The second hides new[] and delete[]. Both of course ensure destruction if + The first hides naked NEW and DELETE from the source code. + The second hides NEW[] and DELETE[]. Both of course ensure destruction if you don't use something like std::move(p) or q.release(). Both expressions require that you identify the type only once, which is brief and less error prone.