aviralgarg05 opened a new pull request, #18308:
URL: https://github.com/apache/nuttx/pull/18308
## Summary
This PR addresses Issue #18232 by improving the compatibility of
`include/cxx/cmath` with external toolchain libraries.
Users reported compilation errors when using external toolchains (e.g.,
MinGW or ARM GCC with incomplete C library integration) where symbols like
`float_t`, `double_t`, `acosf`, etc., are missing from the global namespace in
the toolchain's `<math.h>`.
The fix modifies `include/cxx/cmath` to verify if the underlying environment
provides these symbols before attempting to import them into the `std`
namespace via `using ::symbol`.
Specifically, it uses a checks: `!defined(CONFIG_ARCH_MATH_H) ||
(defined(FLT_EVAL_METHOD) && FLT_EVAL_METHOD == 0)`.
- If `CONFIG_ARCH_MATH_H` is **not** defined (Standard NuttX build): The
code assumes NuttX's internal `math.h` is used, which provides these symbols,
so usage is enabled.
- If `CONFIG_ARCH_MATH_H` **is** defined (External Toolchain): The code
checks for `FLT_EVAL_METHOD`. If missing (common in broken/deficient headers),
it falls back to defining `float_t`/`double_t` manually and skipping the `using
::function` declarations to prevent compilation errors.
## Impact
- **Users**: Enables compilation of C++ applications using `<cmath>` on
platforms/toolchains where the standard C library headers are incomplete or
non-compliant with C99/C++11.
- **Build**: No impact on standard NuttX builds (`sim:nsh`, etc.) because
`CONFIG_ARCH_MATH_H` is typically undefined, preserving the existing behavior.
- **Compatibility**: Improves portability across diverse toolchains.
## Testing
Verified by reproducing the failure in a simulated environment (fake
toolchain missing `float_t`) and confirming the fix allows compilation.
**Host Machine:** macOS (Apple Silicon)
**Target:** Simulator / Generic
### Before Fix (Log)
Compilation failed with errors indicating missing global symbols:
```
In file included from reproduce_issue.cpp:1:
include/cxx/cmath:47:11: error: no member named 'float_t' in the global
namespace
47 | using ::float_t;
| ~~^
include/cxx/cmath:48:11: error: no member named 'double_t' in the global
namespace
48 | using ::double_t;
| ~~^
include/cxx/cmath:51:11: error: no member named 'acosf' in the global
namespace
51 | using ::acosf;
| ~~^
...
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
```
### After Fix (Log)
Compilation succeeded with the simulated external toolchain configuration
(`-DCONFIG_ARCH_MATH_H`):
```
(No output - compilation successful)
```
### Regression Testing
Verified that specific standard NuttX builds are unaffected by checking that
`!defined(CONFIG_ARCH_MATH_H)` path remains valid.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]