Avoid unnecessary std::allocator<void> in MessageMemoryStrategy::create_default() #3436
All Vouch review confidence checks passed
Residual risk 0.27 = Change Risk (0.50) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 618 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.385
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #3436"
general
weight: 0.35
jmachowinski
Description
MessageMemoryStrategy::create_default()previously constructed astd::make_shared<std::allocator<void>>()and passed it to the allocator constructor even for the defaultAlloc = std::allocator<void>. Becausestd::allocator<void>is an empty stateless type, this performs a redundant heap allocation on every default subscription and dereferencing the shared pointer inside the constructor triggers a GCC 15-Werror=uninitializedfalse positive in downstream packages compiled with optimization.Changes:
MessageMemoryStrategy::create_default()inrclcpp/include/rclcpp/message_memory_strategy.hppto call the defaultMessageMemoryStrategy()constructor whenAllocisstd::allocator<void>, while preserving existing behavior for custom allocators.#include <type_traits>torclcpp/include/rclcpp/message_memory_strategy.hppforstd::is_same_v.TEST(TestMemoryStrategies, custom_allocator_create_default)inrclcpp/test/rclcpp/test_message_memory_strategy.cppto cover the custom-allocator branch ofcreate_default().GCC 15 Diagnostic
Observed with
x86_64-conda-linux-gnu-c++ (conda-forge gcc 15.3.0-7) 15.3.0and-std=gnu++23 -O2 -g -DNDEBUG -fPIC -Wall -Wextra -Werroragainstrclcpp(Jazzy28.1.22, wherecreate_default()is atmessage_memory_strategy.hpp:91; identical code onrollingat line 98) in a constructor with multiplecreate_subscription()calls:Applying this patch to
message_memory_strategy.hppeliminated the error on the failing translation unit without needing-Wno-uninitialized.Is this user-facing behavior change?
No
Did you use Generative AI?
Yes, Antigravity (Gemini) assisted with writing the unit test and PR description.
Additional Information
lyrical,jazzy, andhumbleif maintainers would like to backport it.-
ament_uncrustifyandament_cpplintpassed with no issues on both modified files.- Compiled and ran
test_message_memory_strategy.cppwith GCC 15.3.0 (-std=c++17 -O2 -Wall -Wextra -Werror); all 3 tests passed with no warnings.