Skip to content

[libc++] <ctime> std module on windows with ucrt #64812

@Arthapz

Description

@Arthapz

Hello, i tried to build std module on windows but it seems some of the ctime functions are marked static in ucrt so clang fail to export them

e.g

stdmodules/std/ctime.inc:20:14: error: using declaration referring to 'ctime' with internal linkage cannot be exported
   20 |   using std::ctime;
      |              ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\time.h:501:41: note: target of using declaration
  501 |         static __inline char* __CRTDECL ctime(

i got the module to build successfully with patching std/ctime.inc like this

export namespace std {
using std::clock_t;
using std::size_t;
using std::time_t;

using std::timespec;
using std::tm;

using std::asctime;
using std::clock;

#ifdef _UCRT
inline char* __CRTDECL ctime(_In_ time_t const* const _Time) {
  return _ctime64(_Time);
}

inline double __CRTDECL difftime(_In_ time_t const _Time1, _In_ time_t const _Time2) {
  return _difftime64(_Time1, _Time2);
}

inline struct tm* __CRTDECL gmtime(_In_ time_t const* const _Time) {
  return _gmtime64(_Time);
}

inline struct tm* __CRTDECL localtime(_In_ time_t const* const _Time) {
  return _localtime64(_Time);
}

inline time_t __CRTDECL mktime(_Inout_ struct tm* const _Tm) {
  return _mktime64(_Tm);
}
#else
using std::ctime;
using std::difftime;
using std::gmtime;
using std::localtime;
using std::mktime;
#endif

using std::strftime;
#ifdef _UCRT
inline time_t __CRTDECL time(_Out_opt_ time_t* const _Time) {
  return _time64(_Time);
}

inline int __CRTDECL timespec_get(_Out_ struct timespec* const _Ts, _In_ int const _Base) {
  return _timespec64_get((struct _timespec64*)_Ts, _Base);
}
#else
using std::time;
using std::timespec_get;
#endif
} // namespace std

here a self contained reproducer with full logs: https://github.com/Arthapz/libcpp-stdmodule-ctime-errors

Metadata

Metadata

Assignees

Labels

clang:modulesC++20 modules and Clang Header Moduleslibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions