Skip to content

<ctime>: time()/localtime()/mktime() emit error C2129: static function declared but not defined #21

@StephanTLavavej

Description

@StephanTLavavej

Basic Info

  • I have read the rules for the Standard Library Modules Bug Bash.

  • I have pulled and rebuilt the bug-bash branch in the last 24 hours.

  • My current commit, as printed by git rev-parse HEAD, is: 83b0eb5

  • This bug is: rejects-valid

Command-Line Test Case

My test case that works with classic includes but fails with named modules:

D:\GitHub\STL>type purr.cpp
#ifdef USE_CLASSIC_INCLUDES
#include <cstdio>
#include <ctime>
#else
import std;
#endif

#pragma warning(disable : 4996) // CRT deprecation of localtime()

int main() {
#ifdef USE_CLASSIC_INCLUDES
    std::puts("Classic includes.");
#else
    std::puts("Named modules.");
#endif

    const std::time_t now        = std::time(nullptr);
    std::tm local                = *std::localtime(&now);
    const std::time_t round_trip = std::mktime(&local);

    std::printf("                 now: %lld\n", static_cast<long long>(now));
    std::printf("local.tm_year + 1900: %d\n", local.tm_year + 1900);
    std::printf("          round_trip: %lld\n", static_cast<long long>(round_trip));

    std::puts("Done!");
}
D:\GitHub\STL>cl /EHsc /nologo /W4 /std:c++latest /MTd /Od /DUSE_CLASSIC_INCLUDES purr.cpp && purr.exe
purr.cpp
Classic includes.
                 now: 1659072489
local.tm_year + 1900: 2022
          round_trip: 1659072489
Done!

D:\GitHub\STL>cl /EHsc /nologo /W4 /std:c++latest /MTd /Od purr.cpp std.obj && purr.exe
purr.cpp
purr.cpp(27): error C2129: static function 'tm *localtime(const __int64 *const )' declared but not defined
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\time.h(495): note: see declaration of 'localtime'

Additional Context

Found by building tests/tr1/tests/chrono, ctime, cwchar2, locale3, locale4 with modules.

Each of time(), localtime(), mktime() will emit this error if they're the only call in the TU.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions