Skip to content

fix(palette): convert TColorPalette::operator==/!= to hidden friends (#2724) - #2735

Merged
zackees merged 1 commit into
masterfrom
fix/2724-ambiguous-reversed-op-eq
Jun 4, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/2724-ambiguous-reversed-op-eq

Conversation

@zackees

@zackees zackees commented Jun 4, 2026 •

Copy link
Copy Markdown
Member

Closes #2724.

Summary

C++20 -Wambiguous-reversed-operator fires on every CRGBPalette/CHSVPalette equality comparison because the class defined a member operator== and C++20 synthesizes a reversed candidate, leading to an ambiguous best-viable-function diagnosis at every call site. Affects every C++20 build (wasm, wasm_compile_test) and will silently become a compile error as the rest of the matrix migrates to -std=gnu++20.

Fix

Convert both operator== and operator!= on TColorPalette to hidden friends — non-member functions declared inside the class body. The friend form is the recommended C++20 idiom: found only via ADL on the palette type, so no reverse-candidate synthesis applies.

// Before — member, triggers -Wambiguous-reversed-operator under C++20
bool operator==(const TColorPalette &rhs) const FL_NOEXCEPT { ... }

// After — hidden friend, ADL-only, no rewrite candidate considered
friend bool operator==(const TColorPalette &lhs,
                       const TColorPalette &rhs) FL_NOEXCEPT { ... }

Derived classes (TCRGBPalette<16>, CHSVPalette16/32/256, CRGBPalette16/32/256) get these through ADL on the base, so the prior using Base::operator==/!= injections become noise. Removed 14 stale using-declarations across the 7 derived palette classes — they would otherwise dangle on a member that no longer exists.

Why hidden friend and not = default

The issue mentioned bool operator==(const CRGBPalette16&) const = default; as option 1. That works for CRGBPalette16 specifically, but every derived class would need the same boilerplate, and = default requires the underlying member types to support operator== (which CHSV/CRGB already do, but enforces a coupling). The hidden-friend form fixes it once on the base, scales to every derived palette automatically, and is the canonical C++20 idiom.

Test plan

  • bash lint clean
  • bash test fl_gfx_colorutils --cpp passes
  • CI green on wasm + wasm_compile_test (where -Wambiguous-reversed-operator actually fires)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Restructured internal comparison logic for color palettes to improve code organization. No functional changes to end-users.

…2724)

C++20 -Wambiguous-reversed-operator fires on every CRGBPalette/CHSVPalette
equality comparison because the class defined a member operator== and
C++20 synthesizes a reversed candidate, leading to an ambiguous
best-viable-function diagnosis at every call site. Affects every C++20
build (wasm, wasm_compile_test) and will silently become a compile error
as the rest of the matrix migrates to -std=gnu++20.

Fix: convert both operator== and operator!= on TColorPalette to hidden
friends (non-member, declared inside the class body). The friend form is
the recommended C++20 idiom — found only via ADL on the palette type,
so no reverse-candidate synthesis applies. Derived classes get these
through ADL on the base, so the prior `using Base::operator==/!=`
injections become noise; removed 14 stale using-declarations across the
7 derived palette classes (TCRGBPalette<16>, CHSVPalette16/32/256,
CRGBPalette16/32/256).

Closes #2724.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 4, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6b1e5598-98a2-4ab6-a01f-37191215fc3e

📥 Commits

Reviewing files that changed from the base of the PR and between ae6785b and 75a22a5.

📒 Files selected for processing (1)
  • src/fl/gfx/colorutils.h

📝 Walkthrough

Walkthrough

Palette equality operators are refactored from member functions to hidden-friend non-member functions in TColorPalette, resolving C++20 ambiguous-operator warnings. All seven derived palette classes remove their operator using-declarations to rely on ADL.

Changes

Palette Comparison Operators

Layer / File(s) Summary
Base class hidden-friend implementation
src/fl/gfx/colorutils.h
TColorPalette equality operators (operator==, operator!=) are converted from const member functions to hidden-friend non-member functions declared inside the class; comparison logic (pointer-alias fast path and fl::memcmp fallback) is preserved.
Derived palette classes ADL setup
src/fl/gfx/colorutils.h
TCRGBPalette<Size>, CHSVPalette16/32/256, CRGBPalette16/32/256 remove their using Base::operator==; and using Base::operator!=; declarations, leaving only using Base::operator=; and relying on ADL to resolve the base class hidden-friend operators.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • FastLED/FastLED#2363: Modifies palette equality operators and operator resolution in the same TColorPalette and derived palette classes.

Poem

🐰 A friend to compare, not a method in sight,
Hidden in class but still in the light,
ADL finds it when palettes align,
C++20 warnings all declare "we're fine!"

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: converting TColorPalette's equality operators to hidden friends to fix the C++20 -Wambiguous-reversed-operator warning.
Linked Issues check ✅ Passed The PR fully addresses issue #2724 by converting operator== and operator!= to hidden friends on TColorPalette and removing stale using-declarations from derived classes, resolving the C++20 ambiguity.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the C++20 -Wambiguous-reversed-operator issue via hidden friends; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/2724-ambiguous-reversed-op-eq

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zackees
zackees merged commit 2b7ad48 into master Jun 4, 2026
8 of 9 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 4, 2026
@zackees
zackees deleted the fix/2724-ambiguous-reversed-op-eq branch August 21, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

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

1 participant