Repository navigation
fix: make OptionalReference::emplace bind the supplied reference - #228
Merged
alexkaratarakis merged 1 commit intoSep 24, 2026
Merged
alexkaratarakis merged 1 commit into
alexkaratarakis merged 1 commit into
Conversation
alexkaratarakis
force-pushed
the
codex/fix-optional-reference-emplace
branch
from
September 22, 2026 03:45
ebe44e5 to
f676f5d
Compare
Collaborator
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
OptionalReference::emplace()fails to compile even when passed a simpleintlvalue. Itsvalparameter hides the privateval()accessor, so the implementation tries to call the integer as a function.The fix calls
this->val()explicitly and usesstd::addressofto bind the supplied object, just like the existing reference constructor. Rebinding leaves the previous object untouched and does not invoke an overloaded address-of operator.The regression covers first binding, rebinding and returned-reference aliasing,
constand constant-evaluated use, and a type with an overloadedoperator&.This is separate from #221, which adds
and_then,transform, andor_elsebut leavesemplace()unchanged.Testing
Validated on Linux with GCC 13.3 and C++20 in a Debug build using the repository's unmodified top-level CMake project and an isolated CMake CONFIG dependency prefix.
main(d0df5f67e102ba42025ef0ecf761d19a4510a543) at the shadowedval()call, including both constant-evaluated cases.cmake --build build --target optional_reference_test --parallel 4: passed with the repository's-Werrorand-fno-exceptionssettings.ctest --test-dir build --build-config Debug -R '^optional_reference_test$' --output-on-failure: 1/1 target passed, covering all 29 GoogleTest cases in the binary.git diff --checkpassed.Other repository targets, compilers, sanitizers, and platforms were not run for this candidate.