fix(param): bound std::array template switch to MSVC only

The previous switch to std::array<T, N> for parameters_volatile and
parameters_readonly in 044688f8f8 broke NuttX targets, whose libcxx
ships no <array> 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<T, N> 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 <array> 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 <n.marques21@hotmail.com>
This commit is contained in:
Nuno Marques
2026-05-07 17:28:36 -07:00
parent 044688f8f8
commit 03454c81f7
@@ -2,10 +2,13 @@
#include <math.h> // NAN
#include <array>
#include <stdint.h>
#include <parameters/param.h>
#if defined(_MSC_VER) && !defined(__clang__)
# include <array>
#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<T, 0> is standard and supports range-for. #}
{# MSVC rejects "T arr[] = {}" with C2466 ("cannot allocate an array of
constant size 0"). std::array<T, 0> is standard, but NuttX libcxx does
not ship <array>. 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<params, {{ volatile_params|length }}> parameters_volatile = { {
{% for param in volatile_params %}
params::{{ param.attrib["name"] }},
@@ -54,6 +59,19 @@ static constexpr std::array<params, {{ readonly_param_names|length }}> 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