Only on windows, when debugging (gtest) unit tests, JUCE's leak detector warns about StringArrays instantiated with the LeakAvoidanceTrick

Hi!

Only on windows, when debugging (google test) unit tests (in CLion), JUCE’s leak detector warns about StringArrays instantiated with the LeakAvoidanceTrick.

This is both with the develop tip as of yesterday, and with 7.0.10.

This does not happen - with the same exact code - using clang on MacOS, and running the exact same tests.

It’s also specific to the tests. When debugging the same plugin, there’s no leaks detected, neither on Windows nor on Mac.

The StringArrays are created here on start by Juce as far as I understand, here’s the call stack:

juce::`anonymous namespace'::LeakAvoidanceTrick::LeakAvoidanceTrick() juce_LocalisedStrings.cpp:78
juce::`anonymous namespace'::`dynamic initializer for 'leakAvoidanceTrick''() juce_LocalisedStrings.cpp:84
_initterm(void (**)(),void (**)()) 0x00007ff7d61a33a3
__scrt_common_main_seh() 0x00007ff7d609d869
__scrt_common_main() 0x00007ff7d609d7ce
mainCRTStartup(void *) 0x00007ff7d609dabe
<unknown> 0x00007ffb4003257d
<unknown> 0x00007ffb4172aa58

From juce_LocalisedString.cpp:

   #if JUCE_CHECK_MEMORY_LEAKS
    // By using this object to force a LocalisedStrings object to be created
    // before the currentMappings object, we can force the static order-of-destruction to
    // delete the currentMappings object first, which avoids a bogus leak warning.
    // (Oddly, just creating a LocalisedStrings on the stack doesn't work in gcc, it
    // has to be created with 'new' for this to work..)
    struct LeakAvoidanceTrick
    {
        LeakAvoidanceTrick()
        {
            const std::unique_ptr<LocalisedStrings> dummy (new LocalisedStrings (String(), false));
        }
    };

    LeakAvoidanceTrick leakAvoidanceTrick;
   #endif

Since this only happens on windows I’m suspecting a bug in Juce, but of course I may be doing something wrong in the unit tests that only has consequences on Windows?

It happens even in this - simplest - of tests, which I’ve simplified massively to just reproduce the leak detection issue. The peak_meters.cpp file is a simple class which includes JuceHeader.h, nothing complex about it at all, and it only uses some straight-forward Juce containers:

#include "gtest/gtest.h"

#include "peak_meters.cpp"

class PeakMetersTest : public ::testing::Test
{
protected:
    PeakMetersTest() {}

    void SetUp() override
    {
        _moduleUnderTest.reset (new PeakMeters());
        _moduleUnderTest->setSampleRate (48000.f);
    }

    void TearDown() override {}

    std::unique_ptr<PeakMeters> _moduleUnderTest;
};

TEST_F (PeakMetersTest, TestReadWriteParameter)
{
    PeakMeters::ParamId testId = PeakMeters::peakMeterOutLeft;

    bool hasChangedFlag = _moduleUnderTest->_paramValues[testId].load().hasChanged;
    ASSERT_EQ (hasChangedFlag, false);
}

Any ideas on what it can be?

Thank you!