IIRFilter divide by 0 warning

I’ve just started getting a potential divide by 0 warning in IIRFilter::makePeakFilter, probably because of the way A is initialised. Should this be a tiny non-zero value?

I think a peak filter with gain=0 should return an identity, AFAIK returning IIR::Coefficients() would do that.

I got used to it, and I guess everybody got used to it: you cant use 0 for any param in IIRfilter…
there actually should be a jassert(gainFactor > 0.0) there, to keep it in style with the other checks

Yes but the warning is breaking my builds so it either needs to be selectively disabled in juce or the logic fixed so it’s not possible.

Adding an assert won’t help the warning as its optimised out in release builds.
This would help but it’s C++23: C++ attribute: assume (since C++23) - cppreference.com

1 Like

just curious: who gives that warning? I mean, the jasert is for debugging… the release does not need to do such warnings, if you approved of it in debuggin mode. Is it a switch you can turn of in your xocd or visual studio or a compiler flag?
to come back to your original question: You are ofcourse completely correct that A==0 should default to a workable minimal, and not lead to a default divide by 0…

This function looks a bit different on develop - I wonder whether the issue is still present there.

From the screenshot you can see it is a MSVC warning that is only issued when optimisation is enabled, maybe that’s why you didn’t see it yet:

my release mode optimisation level is allways very high, but I am on macos/Xcode. I see no warnings about this…
@reuk : 7.0.5 indeed has the vulnerable A like shown here in OP

Looks the same on develop to me?

I updated juce yesterday. Our fork only has minor changes and tracks juce/develop.

Sorry, I was looking at the one in juce_dsp! I’ll see whether we can repro the warning here.

It appeared when I added these flags to our build:
target_compile_options(${TARGET_NAME} PRIVATE "/fp:fast" "/Oi" "/Oy" "/GF")

1 Like

This should be fixed and available on master. Thanks for reporting.

Thanks! I’ll check that out today

1 Like