Repository navigation
fix(queue_adapter, stack_adapter): return emplaced element reference from emplace - #250
Open
reginaldalfret wants to merge 1 commit into
Conversation
…from emplace Signed-off-by: Reginald Alfret <reginaldalfret@gmail.com>
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
In
queue_adapter.hppandstack_adapter.hpp,emplacedeclares aconstexpr decltype(auto)return type:However, the body was missing a
returnkeyword before invokingIMPLEMENTATION_DETAIL_DO_NOT_USE_data_.emplace_back(...).Because the underlying container's
emplace_back(...)returns areferenceto the emplaced element (e.g.FixedVector::emplace_backandFixedCircularBuffer::emplace_back), omitting thereturnstatement in a non-void function leads to undefined behavior if the caller attempts to use the return value, and deviates from standard C++ container adapter behavior (std::queue::emplaceandstd::stack::emplacein C++17/C++23 returndecltype(auto)/reference).Changes
returntoqueue_adapter::emplace.returntostack_adapter::emplace.test/fixed_queue_test.cpp,test/fixed_stack_test.cpp, andtest/fixed_circular_queue_test.cppverifying the returned reference points to the newly constructed element and supports mutations in-place.