nicolasWDC opened a new issue, #19063:
URL: https://github.com/apache/nuttx/issues/19063

   ### Description / Steps to reproduce the issue
   
   `include/cxx/ctime` does not import `::localtime` into namespace `std`.
   
   NuttX `time.h` provides `localtime` in the global namespace, but the C++ 
`<ctime>` shim only imports a subset of the C time API into `std`.
   
   Current `include/cxx/ctime` contains:
   
   ```cpp
   namespace std
   {
     using ::time_t;
   
     using ::timer_t;
     using ::timespec;
   
     using ::itimerspec;
   
     using ::clock_settime;
     using ::clock_gettime;
     using ::mktime;
     using ::gmtime_r;
     using ::gmtime;
     using ::strftime;
     using ::timer_create;
     using ::timer_delete;
     using ::timer_settime;
     using ::timer_gettime;
     using ::timer_getoverrun;
   }
   ```
   
   As a result, valid C++ code using `std::localtime` fails to compile, even 
though `::localtime` is available.
   
   ## Reproducer
   
   ```cpp
   #include <ctime>
   
   int test_ctime_symbol()
   {
     time_t t = 0;
     auto *tm = std::localtime(&t);
     return tm == nullptr;
   }
   ```
   
   Compile command:
   
   ```sh
   arm-none-eabi-g++ \
     -std=gnu++20 \
     -mlittle-endian -march=armv7e-m -mtune=cortex-m4 \
     -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb \
     -DCONFIG_WCHAR_BUILTIN -D__NuttX__ \
     -isystem /build/nuttx/include/cxx \
     -isystem /build/nuttx/include \
     -c /tmp/test_ctime.cpp -o /tmp/test_ctime.o
   ```
   
   ## Actual behavior
   
   Compilation fails with:
   
   ```text
   error: 'localtime' is not a member of 'std'; did you mean 'locale'?
   ```
   
   A real-world failure occurs when building Botan 3.11.1 against the NuttX C++ 
headers:
   
   ```text
   src/lib/utils/os_utils/os_utils.cpp: In function 'std::string 
Botan::OS::format_time(time_t, const std::string&)':
   src/lib/utils/os_utils/os_utils.cpp:355:23: error: 'localtime' is not a 
member of 'std'; did you mean 'locale'?
     355 |    if(auto tmp = std::localtime(&time)) {
         |                       ^~~~~~~~~
         |                       locale
   ```
   
   ## Expected behavior
   
   `std::localtime` should be available after including `<ctime>`, when 
`::localtime` is provided by NuttX `time.h`.
   
   The reproducer should compile successfully.
   
   ## Suggested fix
   
   Add `using ::localtime;` to `include/cxx/ctime`:
   
   ```diff
   --- include/cxx/ctime
   +++ include/cxx/ctime
   @@
      using ::clock_settime;
      using ::clock_gettime;
      using ::mktime;
   +  using ::localtime;
      using ::gmtime_r;
      using ::gmtime;
      using ::strftime;
   ```
   
   ## Environment
   
   * NuttX version: 12.13.0
   * Target: ARM Cortex-M4 / `xmc4800-relax`
   * Toolchain: `arm-none-eabi-g++`
   * C++ standard: `gnu++20`
   * Configuration:
   
     * `CONFIG_CXX_STANDARD="gnu++20"`
     * NuttX C++ headers included through `/build/nuttx/include/cxx`
     * NuttX C headers included through `/build/nuttx/include`
   
   ## Additional context
   
   This is similar in nature to other C++ shim issues where the C header 
exposes a symbol in the global namespace, but the NuttX C++ wrapper does not 
import it into namespace `std`.
   
   This issue is independent from the C math wrapper. The `<cmath>` path can 
compile successfully, then the build later fails on `<ctime>` because 
`std::localtime` is missing.
   
   
   ### On which OS does this issue occur?
   
   [OS: Linux]
   
   ### What is the version of your OS?
   
   Ubuntu 22.04
   
   ### NuttX Version
   
   12.13.0
   
   ### Issue Architecture
   
   [Arch: arm]
   
   ### Issue Area
   
   [Area: Posix]
   
   ### Host information
   
   _No response_
   
   ### Verification
   
   - [x] I have verified before submitting the report.


-- 
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]

Reply via email to