Clang 14.0.0 (Ninja) - JUCE 8.0.7 - warning ambiguous-reversed-operator

Hello,
I updated JUCE to 8.0.7 and it generates a warning due to “-Wambiguous-reversed-operator” with C++20.

JUCE/modules/juce_gui_basics/juce_gui_basics.cpp:279:
/home/runner/work/Partiels/Partiels/JUCE/modules/juce_gui_basics/components/juce_Component.cpp:2297:20: warning: ISO C++20 considers use of overloaded operator '==' (with operand types 'SafePointer<juce::Component>' and 'const SafePointer<juce::Component>') to be ambiguous despite there being a unique best viable function [-Wambiguous-reversed-operator]
        if (target == originalTarget)
            ~~~~~~ ^  ~~~~~~~~~~~~~~
/home/runner/work/Partiels/Partiels/JUCE/modules/juce_gui_basics/components/juce_Component.h:2417:14: note: ambiguity is between a regular call to this operator and a call with the argument order reversed
        bool operator== (ComponentType* component) const noexcept   { return weakRef == component; }
             ^
1 warning generated.

By the way, it seems to me that target == originalTarget should always be true. Am I missing something?

I’ve looked again and I can’t see how target could be any different from originalTarget. Removing this comparison would remove the warning and simplify the code. Here’s a commit and I can create a PR if that’s OK.

1 Like

It’s not super intuitive, but the HierarchyChecker may reassign target to a parent component in the case that the original target component was destroyed as a result of processing the mouse-up. Therefore, I think it’s preferable to fix the ambiguous operator instead of removing the comparison completely.

Thanks for the explanation! So I replaced with if (target.getComponent() == originalTarget.getComponent()). Let me know if you want a PR but I guess you can do it directly :slight_smile:

Thanks, that’s fixed here:

1 Like