Browse Source

Marked as deprecated: String::empty, var::null, File::nonexistent, ValueTree::invalid and other problematic statically-initialised null values. Please just use the default constructor for these classes!

tags/2021-05-28
jules 7 years ago
parent
commit
8c38c6f57f
14 changed files with 54 additions and 62 deletions
  1. +1
    -2
      examples/Plugins/SamplerPluginDemo.h
  2. +1
    -3
      modules/juce_core/containers/juce_Variant.cpp
  3. +8
    -10
      modules/juce_core/containers/juce_Variant.h
  4. +1
    -3
      modules/juce_core/files/juce_File.cpp
  5. +8
    -15
      modules/juce_core/files/juce_File.h
  6. +22
    -0
      modules/juce_core/system/juce_PlatformDefs.h
  7. +1
    -3
      modules/juce_core/text/juce_String.cpp
  8. +2
    -4
      modules/juce_core/text/juce_String.h
  9. +1
    -3
      modules/juce_data_structures/values/juce_ValueTree.cpp
  10. +2
    -4
      modules/juce_data_structures/values/juce_ValueTree.h
  11. +1
    -3
      modules/juce_graphics/geometry/juce_AffineTransform.cpp
  12. +3
    -5
      modules/juce_graphics/geometry/juce_AffineTransform.h
  13. +1
    -3
      modules/juce_graphics/images/juce_Image.cpp
  14. +2
    -4
      modules/juce_graphics/images/juce_Image.h

+ 1
- 2
examples/Plugins/SamplerPluginDemo.h View File

@@ -2006,8 +2006,7 @@ private:
loopKindLabel { {}, "Looping Mode" };
FileChooser fileChooser { "Select a file to load...",
File::nonexistent,
FileChooser fileChooser { "Select a file to load...", File(),
dataModel.getAudioFormatManager().getWildcardForAllFormats() };
UndoManager* undoManager;


+ 1
- 3
modules/juce_core/containers/juce_Variant.cpp View File

@@ -435,9 +435,7 @@ var::var() noexcept : type (&VariantType_Void::instance) {}
var::var (const VariantType& t) noexcept : type (&t) {}
var::~var() noexcept { type->cleanUp (value); }
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
const var var::null;
#endif
JUCE_DECLARE_DEPRECATED_STATIC (const var var::null);
//==============================================================================
var::var (const var& valueToCopy) : type (valueToCopy.type)


+ 8
- 10
modules/juce_core/containers/juce_Variant.h View File

@@ -274,17 +274,15 @@ 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.
/* 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
JUCE_DEPRECATED_STATIC (static const var null);
private:
//==============================================================================


+ 1
- 3
modules/juce_core/files/juce_File.cpp View File

@@ -63,9 +63,7 @@ File& File::operator= (File&& other) noexcept
return *this;
}
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
const File File::nonexistent;
#endif
JUCE_DECLARE_DEPRECATED_STATIC (const File File::nonexistent);
//==============================================================================
static String removeEllipsis (const String& path)


+ 8
- 15
modules/juce_core/files/juce_File.h View File

@@ -1048,21 +1048,14 @@ public:
bool foldersFirst;
};
#if (! defined(DOXYGEN)) && (! defined (JUCE_GCC))
// Deprecated: use File::getSeparatorChar() and File::getSeparatorString() instead!
JUCE_DEPRECATED (static const juce_wchar separator);
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
/* These static objects are deprecated because it's too easy to accidentally use them indirectly
during a static constructor, which leads to very obscure order-of-initialisation bugs.
Use File::getSeparatorChar() and File::getSeparatorString(), and instead of File::nonexistent,
just use File() or {}.
*/
JUCE_DEPRECATED_STATIC (static const juce_wchar separator);
JUCE_DEPRECATED_STATIC (static const StringRef separatorString);
JUCE_DEPRECATED_STATIC (static const File nonexistent);
private:
//==============================================================================


+ 22
- 0
modules/juce_core/system/juce_PlatformDefs.h View File

@@ -273,6 +273,28 @@ namespace juce
#define JUCE_DEPRECATED_WITH_BODY(functionDef, body) functionDef body
#endif
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
#if ! (defined (DOXYGEN) || defined (JUCE_GCC) || (JUCE_MSVC && _MSC_VER <= 1900))
#define JUCE_DEPRECATED_STATIC(valueDef) JUCE_DEPRECATED (valueDef)
#if JUCE_MSVC
#define JUCE_DECLARE_DEPRECATED_STATIC(valueDef) \
__pragma(warning(push)) \
__pragma(warning(disable:4996)) \
valueDef \
__pragma(warning(pop))
#else
#define JUCE_DECLARE_DEPRECATED_STATIC(valueDef) valueDef
#endif
#else
#define JUCE_DEPRECATED_STATIC(valueDef) valueDef
#define JUCE_DECLARE_DEPRECATED_STATIC(valueDef) valueDef
#endif
#else
#define JUCE_DEPRECATED_STATIC(valueDef)
#define JUCE_DECLARE_DEPRECATED_STATIC(valueDef)
#endif
//==============================================================================
#if JUCE_ANDROID && ! DOXYGEN
#define JUCE_MODAL_LOOPS_PERMITTED 0


+ 1
- 3
modules/juce_core/text/juce_String.cpp View File

@@ -235,9 +235,7 @@ private:
}
};
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
const String String::empty;
#endif
JUCE_DECLARE_DEPRECATED_STATIC (const String String::empty);
//==============================================================================
String::String() noexcept : text (&(emptyString.text))


+ 2
- 4
modules/juce_core/text/juce_String.h View File

@@ -1239,8 +1239,7 @@ 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
/* 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 {}.
@@ -1248,8 +1247,7 @@ public:
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
JUCE_DEPRECATED_STATIC (static const String empty);
private:
//==============================================================================


+ 1
- 3
modules/juce_data_structures/values/juce_ValueTree.cpp View File

@@ -579,9 +579,7 @@ ValueTree::ValueTree() noexcept
{
}
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
const ValueTree ValueTree::invalid;
#endif
JUCE_DECLARE_DEPRECATED_STATIC (const ValueTree ValueTree::invalid);
ValueTree::ValueTree (const Identifier& type) : object (new ValueTree::SharedObject (type))
{


+ 2
- 4
modules/juce_data_structures/values/juce_ValueTree.h View File

@@ -589,12 +589,10 @@ public:
*/
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.
/* An invalid ValueTree that can be used if you need to return one as an error condition, etc.
@deprecated If you need an empty ValueTree object, just use ValueTree() or {}.
*/
static const ValueTree invalid;
#endif
JUCE_DEPRECATED_STATIC (static const ValueTree invalid);
private:
//==============================================================================


+ 1
- 3
modules/juce_graphics/geometry/juce_AffineTransform.cpp View File

@@ -84,9 +84,7 @@ bool AffineTransform::isIdentity() const noexcept
&& mat11 == 1.0f;
}
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
const AffineTransform AffineTransform::identity;
#endif
JUCE_DECLARE_DEPRECATED_STATIC (const AffineTransform AffineTransform::identity);
//==============================================================================
AffineTransform AffineTransform::followedBy (const AffineTransform& other) const noexcept


+ 3
- 5
modules/juce_graphics/geometry/juce_AffineTransform.h View File

@@ -270,12 +270,10 @@ 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 {}.
/* A ready-to-use identity transform - now depracated.
@deprecated If you need an identity transform, just use AffineTransform() or {}.
*/
static const AffineTransform identity;
#endif
JUCE_DEPRECATED_STATIC (static const AffineTransform identity);
//==============================================================================
/* The transform matrix is:


+ 1
- 3
modules/juce_graphics/images/juce_Image.cpp View File

@@ -262,9 +262,7 @@ Image::~Image()
{
}
#if JUCE_ALLOW_STATIC_NULL_VARIABLES
const Image Image::null;
#endif
JUCE_DECLARE_DEPRECATED_STATIC (const Image Image::null);
int Image::getReferenceCount() const noexcept { return image == nullptr ? 0 : image->getSharedCount(); }
int Image::getWidth() const noexcept { return image == nullptr ? 0 : image->width; }


+ 2
- 4
modules/juce_graphics/images/juce_Image.h View File

@@ -414,12 +414,10 @@ 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.
/* 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
JUCE_DEPRECATED_STATIC (static const Image null);
private:
//==============================================================================


Loading…
Cancel
Save