From 85f74ca7d3bd9de59213c912493ccc1573da133b Mon Sep 17 00:00:00 2001 From: jules Date: Sun, 31 Dec 2017 10:49:33 +0000 Subject: [PATCH] Clarified comments around the JUCE_ALLOW_STATIC_NULL_VARIABLES items to make clear that they're deprecated --- .../containers/juce_NamedValueSet.cpp | 4 ---- modules/juce_core/containers/juce_Variant.h | 17 +++++++++---- modules/juce_core/files/juce_File.h | 19 ++++++++------- modules/juce_core/text/juce_String.h | 24 ++++++++++--------- modules/juce_core/text/juce_StringArray.cpp | 4 ---- modules/juce_core/xml/juce_XmlElement.cpp | 4 ---- .../values/juce_ValueTree.cpp | 4 ---- .../values/juce_ValueTree.h | 13 +++++----- .../geometry/juce_AffineTransform.h | 21 ++++++++-------- modules/juce_graphics/images/juce_Image.h | 15 ++++++------ modules/juce_gui_basics/juce_gui_basics.h | 9 ------- 11 files changed, 58 insertions(+), 76 deletions(-) diff --git a/modules/juce_core/containers/juce_NamedValueSet.cpp b/modules/juce_core/containers/juce_NamedValueSet.cpp index ba4ab8b4c0..5a10cfe14f 100644 --- a/modules/juce_core/containers/juce_NamedValueSet.cpp +++ b/modules/juce_core/containers/juce_NamedValueSet.cpp @@ -120,12 +120,8 @@ bool NamedValueSet::isEmpty() const noexcept { return values.isEmpty(); } static const var& getNullVarRef() noexcept { - #if JUCE_ALLOW_STATIC_NULL_VARIABLES - return var::null; - #else static var nullVar; return nullVar; - #endif } const var& NamedValueSet::operator[] (const Identifier& name) const noexcept diff --git a/modules/juce_core/containers/juce_Variant.h b/modules/juce_core/containers/juce_Variant.h index 3a9cb7d24d..a354deac47 100644 --- a/modules/juce_core/containers/juce_Variant.h +++ b/modules/juce_core/containers/juce_Variant.h @@ -64,11 +64,6 @@ public: /** Destructor. */ ~var() noexcept; - #if JUCE_ALLOW_STATIC_NULL_VARIABLES - /** A static var object that can be used where you need an empty variant object. */ - static const var null; - #endif - var (const var& valueToCopy); var (int value) noexcept; var (int64 value) noexcept; @@ -277,6 +272,18 @@ public: */ static var readFromStream (InputStream& input); + #if JUCE_ALLOW_STATIC_NULL_VARIABLES + /** This was a static empty var object, but is now deprecated as it's too easy to accidentally + use it indirectly during a static constructor, leading to hard-to-find order-of-initialisation + problems. + @deprecated If you need a default-constructed var, just use var() or {}. + The only time you might miss having var::null available might be if you need to return an + empty var from a function by reference, but if you need to do that, it's easy enough to use + a function-local static var and return that, avoiding any order-of-initialisation issues. + */ + static const var null; + #endif + private: //============================================================================== class VariantType; friend class VariantType; diff --git a/modules/juce_core/files/juce_File.h b/modules/juce_core/files/juce_File.h index 6917cbbf49..7127327ee8 100644 --- a/modules/juce_core/files/juce_File.h +++ b/modules/juce_core/files/juce_File.h @@ -87,15 +87,6 @@ public: /** Move assignment operator */ File& operator= (File&&) noexcept; - //============================================================================== - #if JUCE_ALLOW_STATIC_NULL_VARIABLES - /** This static constant is used for referring to an 'invalid' file. - Bear in mind that you should avoid this kind of static variable, and always prefer - to use File() or {} if you need a default-constructed File object. - */ - static const File nonexistent; - #endif - //============================================================================== /** Checks whether the file actually exists. @@ -1037,6 +1028,16 @@ public: JUCE_DEPRECATED (static const StringRef separatorString); #endif + //============================================================================== + #if JUCE_ALLOW_STATIC_NULL_VARIABLES + /** This was a static empty File object, but is now deprecated as it's too easy to accidentally + use it indirectly during a static constructor, leading to hard-to-find order-of-initialisation + problems. + @deprecated If you need a default-constructed File object, just use File() or {}. + */ + static const File nonexistent; + #endif + private: //============================================================================== String fullPath; diff --git a/modules/juce_core/text/juce_String.h b/modules/juce_core/text/juce_String.h index 2cd0f6631e..1cd82f35bb 100644 --- a/modules/juce_core/text/juce_String.h +++ b/modules/juce_core/text/juce_String.h @@ -138,17 +138,6 @@ public: /** Destructor. */ ~String() noexcept; - //============================================================================== - #if JUCE_ALLOW_STATIC_NULL_VARIABLES - /** This is a static empty string object that can be used if you need a reference to one. - The value of String::empty is exactly the same as String(), and in almost all cases - it's better to avoid String::empty and just use String() or {} instead, so that the compiler - only has to reason about locally-constructed objects, rather than taking into account - the fact that you're referencing a global shared static memory address. - */ - static const String empty; - #endif - /** This is the character encoding type used internally to store the string. By setting the value of JUCE_STRING_UTF_TYPE to 8, 16, or 32, you can change the @@ -1247,6 +1236,19 @@ public: */ int getReferenceCount() const noexcept; + //============================================================================== + #if JUCE_ALLOW_STATIC_NULL_VARIABLES + /** This was a static empty string object, but is now deprecated as it's too easy to accidentally + use it indirectly during a static constructor, leading to hard-to-find order-of-initialisation + problems. + @deprecated If you need an empty String object, just use String() or {}. + The only time you might miss having String::empty available might be if you need to return an + empty string from a function by reference, but if you need to do that, it's easy enough to use + a function-local static String object and return that, avoiding any order-of-initialisation issues. + */ + static const String empty; + #endif + private: //============================================================================== CharPointerType text; diff --git a/modules/juce_core/text/juce_StringArray.cpp b/modules/juce_core/text/juce_StringArray.cpp index 48571ff9f1..7f11498b8b 100644 --- a/modules/juce_core/text/juce_StringArray.cpp +++ b/modules/juce_core/text/juce_StringArray.cpp @@ -120,12 +120,8 @@ const String& StringArray::operator[] (int index) const noexcept if (isPositiveAndBelow (index, strings.size())) return strings.getReference (index); - #if JUCE_ALLOW_STATIC_NULL_VARIABLES - return String::empty; - #else static String empty; return empty; - #endif } String& StringArray::getReference (int index) noexcept diff --git a/modules/juce_core/xml/juce_XmlElement.cpp b/modules/juce_core/xml/juce_XmlElement.cpp index f1b30acaf6..b8afaf82b2 100644 --- a/modules/juce_core/xml/juce_XmlElement.cpp +++ b/modules/juce_core/xml/juce_XmlElement.cpp @@ -447,12 +447,8 @@ int XmlElement::getNumAttributes() const noexcept static const String& getEmptyStringRef() noexcept { - #if JUCE_ALLOW_STATIC_NULL_VARIABLES - return String::empty; - #else static String empty; return empty; - #endif } const String& XmlElement::getAttributeName (const int index) const noexcept diff --git a/modules/juce_data_structures/values/juce_ValueTree.cpp b/modules/juce_data_structures/values/juce_ValueTree.cpp index 045f631219..54898e0357 100644 --- a/modules/juce_data_structures/values/juce_ValueTree.cpp +++ b/modules/juce_data_structures/values/juce_ValueTree.cpp @@ -688,12 +688,8 @@ ValueTree ValueTree::getSibling (int delta) const noexcept static const var& getNullVarRef() noexcept { - #if JUCE_ALLOW_STATIC_NULL_VARIABLES - return var::null; - #else static var nullVar; return nullVar; - #endif } const var& ValueTree::operator[] (const Identifier& name) const noexcept diff --git a/modules/juce_data_structures/values/juce_ValueTree.h b/modules/juce_data_structures/values/juce_ValueTree.h index 67147a8a28..8243b507fb 100644 --- a/modules/juce_data_structures/values/juce_ValueTree.h +++ b/modules/juce_data_structures/values/juce_ValueTree.h @@ -532,19 +532,18 @@ public: } } + /** Returns the total number of references to the shared underlying data structure that this + ValueTree is using. + */ + int getReferenceCount() const noexcept; + #if JUCE_ALLOW_STATIC_NULL_VARIABLES /** An invalid ValueTree that can be used if you need to return one as an error condition, etc. - This invalid object is equivalent to ValueTree created with its default constructor, but - you should always prefer to avoid it and use ValueTree() or {} instead. + @deprecated If you need an empty ValueTree object, just use ValueTree() or {}. */ static const ValueTree invalid; #endif - /** Returns the total number of references to the shared underlying data structure that this - ValueTree is using. - */ - int getReferenceCount() const noexcept; - private: //============================================================================== JUCE_PUBLIC_IN_DLL_BUILD (class SharedObject) diff --git a/modules/juce_graphics/geometry/juce_AffineTransform.h b/modules/juce_graphics/geometry/juce_AffineTransform.h index d50a103d03..6b3cd0125f 100644 --- a/modules/juce_graphics/geometry/juce_AffineTransform.h +++ b/modules/juce_graphics/geometry/juce_AffineTransform.h @@ -68,20 +68,12 @@ public: /** Compares two transforms. */ bool operator!= (const AffineTransform& other) const noexcept; - #if JUCE_ALLOW_STATIC_NULL_VARIABLES - /** A ready-to-use identity transform. - Note that you should always avoid using a static variable like this, and - prefer AffineTransform() or {} if you need a default-constructed instance. - */ - static const AffineTransform identity; - #endif - //============================================================================== /** Transforms a 2D coordinate using this matrix. */ template void transformPoint (ValueType& x, ValueType& y) const noexcept { - const ValueType oldX = x; + auto oldX = x; x = static_cast (mat00 * oldX + mat01 * y + mat02); y = static_cast (mat10 * oldX + mat11 * y + mat12); } @@ -95,7 +87,7 @@ public: void transformPoints (ValueType& x1, ValueType& y1, ValueType& x2, ValueType& y2) const noexcept { - const ValueType oldX1 = x1, oldX2 = x2; + auto oldX1 = x1, oldX2 = x2; x1 = static_cast (mat00 * oldX1 + mat01 * y1 + mat02); y1 = static_cast (mat10 * oldX1 + mat11 * y1 + mat12); x2 = static_cast (mat00 * oldX2 + mat01 * y2 + mat02); @@ -112,7 +104,7 @@ public: ValueType& x2, ValueType& y2, ValueType& x3, ValueType& y3) const noexcept { - const ValueType oldX1 = x1, oldX2 = x2, oldX3 = x3; + auto oldX1 = x1, oldX2 = x2, oldX3 = x3; x1 = static_cast (mat00 * oldX1 + mat01 * y1 + mat02); y1 = static_cast (mat10 * oldX1 + mat11 * y1 + mat12); x2 = static_cast (mat00 * oldX2 + mat01 * y2 + mat02); @@ -276,6 +268,13 @@ public: */ float getScaleFactor() const noexcept; + #if JUCE_ALLOW_STATIC_NULL_VARIABLES + /** A ready-to-use identity transform - now depracated. + @deprecated If you need an identity transform, just use AffineTransform() or {}. + */ + static const AffineTransform identity; + #endif + //============================================================================== /* The transform matrix is: diff --git a/modules/juce_graphics/images/juce_Image.h b/modules/juce_graphics/images/juce_Image.h index 7f65032e24..a017789d6e 100644 --- a/modules/juce_graphics/images/juce_Image.h +++ b/modules/juce_graphics/images/juce_Image.h @@ -153,14 +153,6 @@ public: */ inline bool isNull() const noexcept { return image == nullptr; } - #if JUCE_ALLOW_STATIC_NULL_VARIABLES - /** A null Image object that can be used when you need to return an invalid image. - This object is the equivalient to an Image created with the default constructor, and - you should always prefer to use Image() or {} when you need an empty image object. - */ - static const Image null; - #endif - //============================================================================== /** Returns the image's width (in pixels). */ int getWidth() const noexcept; @@ -420,6 +412,13 @@ public: /** @internal */ explicit Image (ImagePixelData*) noexcept; + #if JUCE_ALLOW_STATIC_NULL_VARIABLES + /** A null Image object that can be used when you need to return an invalid image. + @deprecated If you need a default-constructed var, just use Image() or {}. + */ + static const Image null; + #endif + private: //============================================================================== ReferenceCountedObjectPtr image; diff --git a/modules/juce_gui_basics/juce_gui_basics.h b/modules/juce_gui_basics/juce_gui_basics.h index bc1240224d..3c79b691ec 100644 --- a/modules/juce_gui_basics/juce_gui_basics.h +++ b/modules/juce_gui_basics/juce_gui_basics.h @@ -117,8 +117,6 @@ namespace juce class MouseInputSource; class MouseInputSourceInternal; class ComponentPeer; - class MarkerList; - class RelativeRectangle; class MouseEvent; struct MouseWheelDetails; struct PenDetails; @@ -130,28 +128,21 @@ namespace juce class ComboBox; class Button; class FilenameComponent; - class DocumentWindow; class ResizableWindow; - class GroupComponent; class MenuBarComponent; - class DropShadower; class GlyphArrangement; - class PropertyComponent; class TableHeaderComponent; class Toolbar; - class ToolbarItemComponent; class PopupMenu; class ProgressBar; class FileBrowserComponent; class DirectoryContentsDisplayComponent; class FilePreviewComponent; - class ImageButton; class CallOutBox; class Drawable; class DrawablePath; class DrawableComposite; class CaretComponent; - class BubbleComponent; class KeyPressMappingSet; class ApplicationCommandManagerListener; class DrawableButton;