Breaking change (minor): String (bool) constructor explicitly deleted

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 platforms. Now the behaviour is consistent across all operating systems supported by JUCE.

6 Likes

Hi Tom, noticed today another difference.

A uint8 will get automatically cast to an int on OSX whereas an explicit cast is needed on Windows.

e.g.

uint8 len = 55;
DBG( "len: " << len );

is ok on OSX, whereas:

DBG( "len: " << (int)len );

is needed on Windows. Should probably make these consistent also?

Cheers

1 Like

Has this been tested on Linux with ASIO enabled?
I’m getting these errors back from my build server:

Compiling include_juce_audio_processors.cpp
In file included from ../../../modules/juce/modules/juce_audio_devices/juce_audio_devices.cpp:200:0,
                from ../../JuceLibraryCode/include_juce_audio_devices.cpp:9:
../../../modules/juce/modules/juce_audio_devices/native/juce_linux_ALSA.cpp: In constructor ‘juce::{anonymous}::ALSADevice::ALSADevice(const juce::String&, bool)’:
../../../modules/juce/modules/juce_audio_devices/native/juce_linux_ALSA.cpp:158:95: error: use of deleted function ‘juce::String& juce::operator<<(juce::String&, bool)’
        JUCE_ALSA_LOG ("snd_pcm_open (" << deviceID.toUTF8().getAddress() << ", forInput=" << forInput << ")");
                                                                                              ^
../../../modules/juce/modules/juce_audio_devices/native/juce_linux_ALSA.cpp:31:87: note: in definition of macro ‘JUCE_ALSA_LOG’
 #define JUCE_ALSA_LOG(dbgtext)   { juce::String tempDbgBuf ("ALSA: "); tempDbgBuf << dbgtext; Logger::writeToLog (tempDbgBuf); DBG (tempDbgBuf); }
                                                                                      ^
In file included from ../../../modules/juce/modules/juce_core/juce_core.h:213:0,
                from ../../../modules/juce/modules/juce_events/juce_events.h:50,
                from ../../../modules/juce/modules/juce_audio_devices/juce_audio_devices.h:54,
                from ../../../modules/juce/modules/juce_audio_devices/juce_audio_devices.cpp:46,
                from ../../JuceLibraryCode/include_juce_audio_devices.cpp:9:
../../../modules/juce/modules/juce_core/text/juce_String.h:1349:32: note: declared here
JUCE_API String& JUCE_CALLTYPE operator<< (String&, bool) = delete;
                               ^
In file included from ../../../modules/juce/modules/juce_audio_devices/juce_audio_devices.cpp:200:0,
                from ../../JuceLibraryCode/include_juce_audio_devices.cpp:9:
../../../modules/juce/modules/juce_audio_devices/native/juce_linux_ALSA.cpp: In static member function ‘static juce::AudioData::Converter* juce::{anonymous}::ALSADevice::createConverter(bool, int, bool, bool, bool, int)’:
../../../modules/juce/modules/juce_audio_devices/native/juce_linux_ALSA.cpp:421:75: error: use of deleted function ‘juce::String& juce::operator<<(juce::String&, bool)’
        JUCE_ALSA_LOG ("format: bitDepth=" << bitDepth << ", isFloat=" << isFloat
                                                                          ^
../../../modules/juce/modules/juce_audio_devices/native/juce_linux_ALSA.cpp:31:87: note: in definition of macro ‘JUCE_ALSA_LOG’
 #define JUCE_ALSA_LOG(dbgtext)   { juce::String tempDbgBuf ("ALSA: "); tempDbgBuf << dbgtext; Logger::writeToLog (tempDbgBuf); DBG (tempDbgBuf); }

It’s a breaking change as documented, you need to go and cast your bools to int explicitly, e.g. I’m assuming ‘isFloat’ is a bool?

But the log shows this is in JUCE code, so presumably they need to cast the bools.
I imagine there just isn’t CI coverage for Linux ALSA?

2 Likes

You can just cast it to a bool and they’ll update the repos when they get back to work… they must have missed that.

Thanks for reporting it.

Rail

ah, ok, sorry - didn’t realise that was their code…

We didn’t have debug logging turned on for our tests…