RTEMS | libdebugger/rtems-debugger-arm.c: Warning for using defined() in expansion (#5328)

Joel Sherrill (@joel) gitlab at rtems.org
Wed Sep 3 18:27:56 UTC 2025



Joel Sherrill created an issue: https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5328

Assignee: Chris Johns

## Summary
The definition of NEEDS_THUMB_SWITCH is not portable and flagged by _-Wexpansion-to-defined_ which is documented as follows:

> Warn whenever ‘defined’ is encountered in the expansion of a macro (including the case where the macro is expanded by an ‘#if’ directive). Such usage is not portable. This warning is also enabled by -Wpedantic and -Wextra.
 
The warning is:

```
../../../cpukit/libdebugger/rtems-debugger-arm.c:85:5: warning: this use of 'defined' may not be portable [-Wexpansion-to-defined]
   85 | #if NEEDS_THUMB_SWITCH
      |     ^~~~~~~~~~~~~~~~~~
```

This is the definition of NEEDS_THUMB_SWITCH:

`#define NEEDS_THUMB_SWITCH !ARM_THUMB_ONLY && defined(__thumb__)`

I think this needs to be restructured so NEEDS_THUMB_SWITCH is set to true or false directly rather than expanding to the conditional. Perhaps something like this with XXX and YYY replaced with 0 or 1 appropriately:

```
#if !ARM_THUMB_ONLY && defined(__thumb__)`
#define NEEDS_THUMB_SWITCH XXX
#else
#endif
#define NEEDS_THUMB_SWITCH YYY
#endif
```

## Steps to reproduce

Per the cited documentation, this is an extra warning. I am looking through logs with -Wextra to see what are low volume warning flags. 

### Pre-set options

-- 
View it on GitLab: https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5328
You're receiving this email because of your account on gitlab.rtems.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/bugs/attachments/20250903/5d534414/attachment.htm>


More information about the bugs mailing list