From 03454c81f7b05eef6b72927a68a45a4c1c614891 Mon Sep 17 00:00:00 2001 From: Nuno Marques Date: Thu, 7 May 2026 17:28:36 -0700 Subject: [PATCH] fix(param): bound std::array template switch to MSVC only The previous switch to std::array for parameters_volatile and parameters_readonly in 044688f8f8 broke NuttX targets, whose libcxx ships no header. Re-introduce the gate that 2f167b9d57 had: keep the C-array form (T arr[] = {}) for GCC/Clang/NuttX where the GCC extension is accepted, and use std::array only on real MSVC, which is the only compiler that flags the empty form with C2466 ("cannot allocate an array of constant size 0"). Detect MSVC as `_MSC_VER && !__clang__` so clang-cl, which accepts the GCC extension, falls into the C-array branch alongside everyone else. The include is gated to the MSVC branch as well so NuttX libcxx is never asked for it. Range-for in parameters_common.cpp works on both forms; no consumer changes. Signed-off-by: Nuno Marques --- .../templates/px4_parameters.hpp.jinja | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/lib/parameters/templates/px4_parameters.hpp.jinja b/src/lib/parameters/templates/px4_parameters.hpp.jinja index c215552185..ad2ed9be4d 100644 --- a/src/lib/parameters/templates/px4_parameters.hpp.jinja +++ b/src/lib/parameters/templates/px4_parameters.hpp.jinja @@ -2,10 +2,13 @@ #include // NAN -#include #include #include +#if defined(_MSC_VER) && !defined(__clang__) +# include +#endif + // DO NOT EDIT // This file is autogenerated from parameters.xml @@ -39,10 +42,12 @@ static constexpr param_type_t parameters_type[] = { {%- endfor -%} }; -{# Use std::array so that an empty list (size 0) is well-formed on all - compilers. A C-style "T arr[] = {}" is a GCC/Clang extension; MSVC - rejects it with C2466 ("cannot allocate an array of constant size 0"). - std::array is standard and supports range-for. #} +{# MSVC rejects "T arr[] = {}" with C2466 ("cannot allocate an array of + constant size 0"). std::array is standard, but NuttX libcxx does + not ship . Use std::array on MSVC only and keep the GCC/Clang + extension form everywhere else. Range-for in parameters_common.cpp works + on both. #} +#if defined(_MSC_VER) && !defined(__clang__) static constexpr std::array parameters_volatile = { { {% for param in volatile_params %} params::{{ param.attrib["name"] }}, @@ -54,6 +59,19 @@ static constexpr std::array parameter params::{{ param_name }}, {% endfor %} } }; +#else +static constexpr params parameters_volatile[] = { +{% for param in volatile_params %} + params::{{ param.attrib["name"] }}, +{% endfor %} +}; + +static constexpr params parameters_readonly[] = { +{% for param_name in readonly_param_names %} + params::{{ param_name }}, +{% endfor %} +}; +#endif } // namespace px4