include/macro.h: fix REVERSE_ARG/FOREACH_ARG for empty args in C++ - #20023
include/macro.h: fix REVERSE_ARG/FOREACH_ARG for empty args in C++#20023xiaoxiang781216 wants to merge 1 commit into
Conversation
C++ strict mode drops the GNU ", ##__VA_ARGS__" comma elision, so GET_ARG_COUNT() and REVERSE_ARG() misselect their dispatch entry with zero varargs. Centralize the empty-argument handling in GET_ARG_COUNT (via __VA_OPT__ for C++) and make REVERSE_ARG and FOREACH_ARG dispatch through CONCATENATE(prefix, GET_ARG_COUNT(...)), removing the two duplicated 33-entry selector lists. Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
|
@xiaoxiang781216 and about this PR: I just asked him to submit the loadelfdemo to let us have a way to test it and he close the PR without any explanation. If they don't want to fix PRs, add documentation or test to validate the implementation, why are they submitting PRs? It is not fair for those who are here (like you and me) trying to make NuttX better. |
the fix isn't good, and need more refine then upstream again. |
Summary
, ##__VA_ARGS__comma elision extension, soGET_ARG_COUNT()returns 1 instead of 0 for the zero-argument case, which makesREVERSE_ARG()andFOREACH_ARG()misselect their dispatch entry with zero varargs.GET_ARG_COUNT(via__VA_OPT__for C++) and makeREVERSE_ARGandFOREACH_ARGdispatch throughCONCATENATE(prefix, GET_ARG_COUNT(...)).REVERSE_ARG_andFOREACH_ARG_) as a side benefit.Impact
include/nuttx/macro.his touched; no new configuration options., ##__VA_ARGS__); the C++ path now uses standard__VA_OPT__(available since C++20, and as an extension in GNU C++ modes of GCC/Clang).include/nuttx/sched_note.h(NOTE_PRINTF_TYPES,NOTE_PRINTF_TAG), which is exercised bysched_note_printf()whenCONFIG_DRIVERS_NOTE_STRIP_FORMATis enabled.Testing
Built and booted
sim:nshwith this change:Standalone macro test comparing the old and the new header (the
NOTE_PRINTF_TAGpattern fromsched_note.h):The C behavior is identical before and after the change (
gcc -std=gnu11givestag0=0with both headers).