Error in juce_NormalisableRange.h


#1

Juce v4.3.1-5-g95085c1. Test project is compiled with all sorts of warnings enabled. However, I’m getting one in particular in some JUCE code:

modules/juce_core/maths/juce_NormalisableRange.h:132:13: error: this ‘if’ clause does not guard... [-Werror=misleading-indentation]
            if (skew != static_cast<ValueType> (1) && proportion > ValueType())
            ^~
modules/juce_core/maths/juce_NormalisableRange.h:135:17: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘if’
                return start + (end - start) * proportion;

Is the return part of the if()? Or is it outside of the if()? The indentation and lack of {} is confusing. Interesting of g++ to bring it up.


#2

Thanks - the code’s semantically correct, but I’ll fix the messed-up indentation (tut tut!)

Although not a problem in this case, it’s nice that g++ is flagging stuff like that based on the indentation! I don’t think we have any test builds in our CI server that use g++, maybe we should add one…


#3

Hey im also using g++, got a few warnings from juce code:

|| ../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp: In static member function 'static void juce::AiffAudioFormatReader::copySampleData(unsigned int, bool, int* const*, int, int, const void*, int, int)':
/home/linuxUser/code/juce_Project/Builds/LinuxMakefile/../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp|619 col 25| warning: this 'else' clause does not guard... [-Wmisleading-indentation]
||                          else                       ReadHelper<AudioData::Int32,   AudioData::Int32,   Endianness>::read (destSamples, startOffsetInDestBuffer, numDestChannels, sourceData, numChannels, numSamples); break;^M
||                          ^~~~
/home/linuxUser/code/juce_Project/Builds/LinuxMakefile/../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp|619 col 215| note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
||                          else                       ReadHelper<AudioData::Int32,   AudioData::Int32,   Endianness>::read (destSamples, startOffsetInDestBuffer, numDestChannels, sourceData, numChannels, numSamples); break;^M
||                                                                                                                                                                                                                        ^~~~~
|| ../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp: In member function 'virtual void juce::MemoryMappedAiffReader::getSample(juce::int64, float*) const':
/home/linuxUser/code/juce_Project/Builds/LinuxMakefile/../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp|872 col 29| warning: this 'else' clause does not guard... [-Wmisleading-indentation]
||                              else                       ReadHelper<AudioData::Float32, AudioData::Int32,   AudioData::LittleEndian>::read (dest, 0, 1, source, 1, num); break;^M
||                              ^~~~
/home/linuxUser/code/juce_Project/Builds/LinuxMakefile/../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp|872 col 168| note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
||                              else                       ReadHelper<AudioData::Float32, AudioData::Int32,   AudioData::LittleEndian>::read (dest, 0, 1, source, 1, num); break;^M
||                                                                                                                                                                         ^~~~~
/home/linuxUser/code/juce_Project/Builds/LinuxMakefile/../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp|884 col 29| warning: this 'else' clause does not guard... [-Wmisleading-indentation]
||                              else                       ReadHelper<AudioData::Float32, AudioData::Int32,   AudioData::BigEndian>::read (dest, 0, 1, source, 1, num); break;^M
||                              ^~~~
/home/linuxUser/code/juce_Project/Builds/LinuxMakefile/../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp|884 col 165| note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
||                              else                       ReadHelper<AudioData::Float32, AudioData::Int32,   AudioData::BigEndian>::read (dest, 0, 1, source, 1, num); break;^M
||                                                                                                                                                                      ^~~~~
|| ../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp: In member function 'virtual void juce::MemoryMappedAiffReader::readMaxLevels(juce::int64, juce::int64, juce::Range<float>*, int)':
/home/linuxUser/code/juce_Project/Builds/LinuxMakefile/../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp|910 col 25| warning: this 'else' clause does not guard... [-Wmisleading-indentation]
||                          else                       scanMinAndMax<AudioData::Int32>   (startSampleInFile, numSamples, results, numChannelsToRead); break;^M
||                          ^~~~
/home/linuxUser/code/juce_Project/Builds/LinuxMakefile/../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_AiffAudioFormat.cpp|910 col 147| note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
||                          else                       scanMinAndMax<AudioData::Int32>   (startSampleInFile, numSamples, results, numChannelsToRead); break;^M
||                                                                                                                                                    ^~~~~
|| ../../JuceLibraryCode/modules/juce_audio_formats/codecs/oggvorbis/libvorbis-1.3.2/lib/vorbisfile.c: In function 'int juce::OggVorbisNamespace::ov_pcm_seek_page(juce::OggVorbisNamespace::OggVorbis_File*, juce::OggVorbisNamespace::ogg_int64_t)':
/home/linuxUser/code/juce_Project/Builds/LinuxMakefile/../../JuceLibraryCode/modules/juce_audio_formats/codecs/oggvorbis/libvorbis-1.3.2/lib/vorbisfile.c|1566 col 10| warning: this 'else' clause does not guard... [-Wmisleading-indentation]
||          }else^M
||           ^~~~
/home/linuxUser/code/juce_Project/Builds/LinuxMakefile/../../JuceLibraryCode/modules/juce_audio_formats/codecs/oggvorbis/libvorbis-1.3.2/lib/vorbisfile.c|1568 col 11| note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
||            (void) result;^M
||            ^
|| ../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp: In static member function 'static void juce::WavAudioFormatReader::copySampleData(unsigned int, bool, int* const*, int, int, const void*, int, int)':
/home/linuxUser/code/juce_Project/Builds/LinuxMakefile/../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp|1200 col 25| warning: this 'else' clause does not guard... [-Wmisleading-indentation]
||                          else                       ReadHelper<AudioData::Int32,   AudioData::Int32,   AudioData::LittleEndian>::read (destSamples, startOffsetInDestBuffer, numDestChannels, sourceData, numChannels, numSamples); break;^M
||                          ^~~~
/home/linuxUser/code/juce_Project/Builds/LinuxMakefile/../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp|1200 col 228| note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
||                          else                       ReadHelper<AudioData::Int32,   AudioData::Int32,   AudioData::LittleEndian>::read (destSamples, startOffsetInDestBuffer, numDestChannels, sourceData, numChannels, numSamples); break;^M
||                                                                                                                                                                                                                                     ^~~~~
|| ../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp: In member function 'virtual void juce::MemoryMappedWavReader::getSample(juce::int64, float*) const':
/home/linuxUser/code/juce_Project/Builds/LinuxMakefile/../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp|1518 col 25| warning: this 'else' clause does not guard... [-Wmisleading-indentation]
||                          else                       ReadHelper<AudioData::Float32, AudioData::Int32,   AudioData::LittleEndian>::read (dest, 0, 1, source, 1, num); break;^M
||                          ^~~~
/home/linuxUser/code/juce_Project/Builds/LinuxMakefile/../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp|1518 col 164| note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
||                          else                       ReadHelper<AudioData::Float32, AudioData::Int32,   AudioData::LittleEndian>::read (dest, 0, 1, source, 1, num); break;^M
||                                                                                                                                                                     ^~~~~
|| ../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp: In member function 'virtual void juce::MemoryMappedWavReader::readMaxLevels(juce::int64, juce::int64, juce::Range<float>*, int)':
/home/linuxUser/code/juce_Project/Builds/LinuxMakefile/../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp|1543 col 25| warning: this 'else' clause does not guard... [-Wmisleading-indentation]
||                          else                       scanMinAndMax<AudioData::Int32>   (startSampleInFile, numSamples, results, numChannelsToRead); break;^M
||                          ^~~~
/home/linuxUser/code/juce_Project/Builds/LinuxMakefile/../../JuceLibraryCode/modules/juce_audio_formats/codecs/juce_WavAudioFormat.cpp|1543 col 147| note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'                                                                              
||                          else                       scanMinAndMax<AudioData::Int32>   (startSampleInFile, numSamples, results, numChannelsToRead); break;^M
||                                                                                                                                                    ^~~~~

No Erros, just warning, but this good feeling of compiling my software without any errors and warnings is a little smaller with those errors! :wink:

Greetz equinox


#4

Well, the warnings are definitely false alarms, but thanks for telling us, we should restructure things to silence them!