Skip to content

C++20: -Wambiguous-reversed-operator on TColorPalette::operator== (colorutils.h:486) — make hidden friend or add operator!= #2724

Closed

Description

@zackees

Summary

C++20 -Wambiguous-reversed-operator fires on CRGBPalette16 == CRGBPalette16 because the class defines a member operator== and C++20 synthesizes a reversed candidate, leading to an ambiguous best-viable-function diagnosis at every call site.

warning: ISO C++20 considers use of overloaded operator == (with operand types
  CRGBPalette16 and CRGBPalette16) to be ambiguous despite there being a unique
  best viable function [-Wambiguous-reversed-operator]

  defining op:  src/fl/gfx/colorutils.h:486
  call site:    src/fl/fx/2d/noisepalette.h:78  ->  do { ... } while (newPalette == currentPalette);

Root cause: CRGBPalette16 brings in Base::operator== via using, and the reverse-order resolution becomes ambiguous under C++20.

Why this matters

Affects every C++20 build (wasm, wasm_compile_test today; the rest of the matrix will inherit it as toolchains default to -std=gnu++20). Will silently change to a compile error when fbuild upgrades the wasm toolchain to a stricter C++20 mode.

Proposed fix

Two clean options:

  1. Add explicit bool operator==(const CRGBPalette16&) const = default; on CRGBPalette16.
  2. Make operator== a hidden friend (non-member declared inside the class body) — recommended C++20 idiom:
friend bool operator==(const TColorPalette& a, const TColorPalette& b) { ... }

The friend form is the most future-proof.

Evidence

wasm + wasm_compile_test runs surface this on every TU that includes fl/fx/2d/noisepalette.h.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions