Skip to content

fix(stl/variant): emplace<T>() returns T& not T* - #2783

Merged
zackees merged 1 commit into
masterfrom
fix/variant-emplace-return-type
Jun 5, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/variant-emplace-return-type

Conversation

@zackees

@zackees zackees commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

Summary

fl::variant::emplace<T>(Args&&...) is declared to return T& but the body was return ptr<T>(); (where ptr<T>() returns T*). The mismatch was latent because emplace had no in-tree users — the error surfaced the moment something actually called it (in my case, while attempting #2773 item 1.4):

src/fl/stl/variant.h:102:22: error: invalid initialization of non-const reference of type
'fl::enable_if<true, fl::UartEsp32&>::type' {aka 'fl::UartEsp32&'} from an rvalue of type
'fl::UartEsp32*'

One-character fix: dereference the pointer.

Tests

  • bash test variant --cpp — 1/1 passes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a return value issue in a utility function to properly align with its declared return type, ensuring correct behavior for library users.

`fl::variant::emplace<T>(Args&&...)` is declared to return `T&` but the body
was `return ptr<T>();` (which returns `T*`). The error was only flagged by
the compiler when emplace got actually instantiated — which happened first
while attempting #2773 item 1.4 (`EspIO` variant-based driver selection):

    src/fl/stl/variant.h:102:22: error: invalid initialization of non-const
    reference of type 'fl::enable_if<true, fl::UartEsp32&>::type'
    {aka 'fl::UartEsp32&'} from an rvalue of type 'fl::UartEsp32*'

One-character fix: dereference the pointer in the return statement so the
returned type matches the signature.

No existing callers were affected because emplace had zero in-tree
users — host tests still pass (`bash test variant --cpp` → 1/1).

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

coderabbitai Bot commented Jun 5, 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: 6bb267aa-fcf5-48a8-8354-fd1b29dcd259

📥 Commits

Reviewing files that changed from the base of the PR and between a4bdea8 and 454d1e9.

📒 Files selected for processing (1)
  • src/fl/stl/variant.h

📝 Walkthrough

Walkthrough

The pull request fixes a bug in the fl::variant::emplace function where the return statement was returning a pointer instead of a reference. The function signature declares a T& return type, and the fix dereferences the pointer to align the actual return with the declared type.

Changes

variant::emplace Return Type Fix

Layer / File(s) Summary
emplace reference return
src/fl/stl/variant.h
emplace return statement corrected to dereference ptr<T>() and return *ptr<T>(), providing a reference to the newly constructed object instead of a pointer.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~1 minute

Poem

A pointer so proud tried to hide,
But dereference turned the tide!
Now emplace shines bright and true,
With T& returned just for you—
One star fix makes the variant complete! ⭐

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: correcting the return type of emplace() from a pointer (T*) to a reference (T&), which directly matches the one-character change in the implementation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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/variant-emplace-return-type

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 13f071a into master Jun 5, 2026
8 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 5, 2026
@zackees
zackees deleted the fix/variant-emplace-return-type branch August 21, 2026 19:16
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.

1 participant