From b8cf40be2f9196315ef89b26daa9c58a2994ffbc Mon Sep 17 00:00:00 2001 From: Kevin Ahrendt Date: Wed, 12 Aug 2026 07:25:15 -0400 Subject: [PATCH] Silence a GCC dangling-reference warning in controller parsing GCC emits -Wdangling-reference for the supported_commands range-for in process_server_state_controller(), and it fires on every ESP-IDF build of the component: warning: possibly dangling reference to a temporary note: 'MemberProxy' temporary created here The range initializer chained .as() off the MemberProxy temporary returned by operator[]. Only the final temporary gets lifetime extension, so the proxy dies at the end of the full-expression while the loop is still running. It was benign: JsonArrayConst stores a const ArrayData* and a const ResourceManager*, both pointing into the JsonDocument's memory pool, and JsonArrayConstIterator holds an ArrayData::iterator plus that same resource pointer. Nothing reads back through the dead proxy. GCC's heuristic cannot see that, so bind the array to a named local instead of suppressing the diagnostic. This also matches what the file already does everywhere else. The five other array loops (active_roles, artwork channels, visualizer types, and both stream roles lists) already name a local first; this was the only chained range initializer left. Verified with g++ 15 on the host include set: the warning reproduces before the change and no -Wdangling-reference remains across src/ or src/host/ after it. Host clang build and all 123 tests still pass. --- src/protocol.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/protocol.cpp b/src/protocol.cpp index fa35e0f..eace564 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -550,8 +550,9 @@ bool process_server_state_controller(JsonObject root, // command is a non-compliant value rather than a forward-compatible one: drop and log it. if (controller_object["supported_commands"].is()) { std::vector commands; - for (JsonVariantConst command_var : - controller_object["supported_commands"].as()) { + JsonArrayConst commands_array = + controller_object["supported_commands"].as(); + for (JsonVariantConst command_var : commands_array) { if (auto command = read_enum_field(command_var, "supported_commands", controller_command_from_string)) { commands.push_back(*command);