Repository navigation
fix(palette): convert TColorPalette::operator==/!= to hidden friends (#2724) - #2735
Conversation
…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]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughPalette equality operators are refactored from member functions to hidden-friend non-member functions in ChangesPalette Comparison Operators
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Closes #2724.
Summary
C++20
-Wambiguous-reversed-operatorfires on everyCRGBPalette/CHSVPaletteequality comparison because the class defined a memberoperator==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==andoperator!=onTColorPaletteto 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.Derived classes (
TCRGBPalette<16>,CHSVPalette16/32/256,CRGBPalette16/32/256) get these through ADL on the base, so the priorusing 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
= defaultThe issue mentioned
bool operator==(const CRGBPalette16&) const = default;as option 1. That works forCRGBPalette16specifically, but every derived class would need the same boilerplate, and= defaultrequires the underlying member types to supportoperator==(whichCHSV/CRGBalready 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 lintcleanbash test fl_gfx_colorutils --cpppasses-Wambiguous-reversed-operatoractually fires)🤖 Generated with Claude Code
Summary by CodeRabbit