diff --git a/BREAKING-CHANGES.txt b/BREAKING-CHANGES.txt index c6aea72e5b..54bfe9846e 100644 --- a/BREAKING-CHANGES.txt +++ b/BREAKING-CHANGES.txt @@ -4,6 +4,29 @@ JUCE breaking changes Develop Branch ============= +Change +------ +The String (bool) constructor and operator<< (String&, bool) have been +explicitly deleted. + +Possible Issues +--------------- +Previous code which relied on an implicit bool to int type conversion to +produce a String will not compile. + +Workaround +---------- +Cast your bool to an integer to generate a string representation of it. + +Rationale +--------- +Letting things implicitly convert to bool to produce a String opens the door to +all kinds of nasty type conversion edge cases. Furthermore, before this change, +MacOS would automatically convert bools to ints but this wouldn't occur on +different platform. Now the behaviour is consistent across all operating +systems supported by JUCE. + + Change ------ The writeAsJSON virtual method of the DynamicObject class requires an diff --git a/modules/juce_core/memory/juce_HeapBlock.h b/modules/juce_core/memory/juce_HeapBlock.h index fdc10c9542..5bb5aa9657 100644 --- a/modules/juce_core/memory/juce_HeapBlock.h +++ b/modules/juce_core/memory/juce_HeapBlock.h @@ -149,6 +149,13 @@ public: */ inline operator ElementType*() const noexcept { return data; } + + /** Returns a raw pointer to the allocated data. + This may be a null pointer if the data hasn't yet been allocated, or if it has been + freed by calling the free() method. + */ + inline ElementType* get() const noexcept { return data; } + /** Returns a raw pointer to the allocated data. This may be a null pointer if the data hasn't yet been allocated, or if it has been freed by calling the free() method. diff --git a/modules/juce_core/text/juce_String.cpp b/modules/juce_core/text/juce_String.cpp index ea96c60f3b..d66b945693 100644 --- a/modules/juce_core/text/juce_String.cpp +++ b/modules/juce_core/text/juce_String.cpp @@ -868,8 +868,6 @@ JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const uint64 number) JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const float number) { return s1 += String (number); } JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, const double number) { return s1 += String (number); } -JUCE_API String& JUCE_CALLTYPE operator<< (String& s1, bool b) { return s1 += String (b); } - JUCE_API OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const String& text) { return operator<< (stream, StringRef (text)); @@ -1886,7 +1884,7 @@ String String::formattedRaw (const char* pf, ...) va_end (args); if (num > 0) - return String (temp); + return String (temp.get()); bufferSize += 256; diff --git a/modules/juce_core/text/juce_String.h b/modules/juce_core/text/juce_String.h index 1cc80e97d8..885256b322 100644 --- a/modules/juce_core/text/juce_String.h +++ b/modules/juce_core/text/juce_String.h @@ -987,6 +987,10 @@ public: */ String (double doubleValue, int numberOfDecimalPlaces); + // Automatically creating a String from a bool opens up lots of nasty type conversion edge cases. + // If you want a String representation of a bool you can cast the bool to an int first. + explicit String (bool) = delete; + /** Reads the value of the string as a decimal number (up to 32 bits in size). @returns the value of the string as a 32 bit signed base-10 integer. @@ -1340,8 +1344,9 @@ JUCE_API String& JUCE_CALLTYPE operator<< (String& string1, float number); /** Appends a decimal number to the end of a string. */ JUCE_API String& JUCE_CALLTYPE operator<< (String& string1, double number); -/** Appends a boolean to the end of a string. */ -JUCE_API String& JUCE_CALLTYPE operator<< (String& string1, bool boolean); +// Automatically creating a String from a bool opens up lots of nasty type conversion edge cases. +// If you want a String representation of a bool you can cast the bool to an int first. +JUCE_API String& JUCE_CALLTYPE operator<< (String&, bool) = delete; //============================================================================== /** Case-sensitive comparison of two strings. */