Skip to content

MSVC hardened build fails: /sdl makes C4996 (fopen, gmtime, strncpy...) an error #380

Closed

Description

@homer6

Found by the v0.5.0 fix-up run (https://github.com/homer6/cpp-docs/actions/runs/41689101415), tracking #363. The job never got past checkout in the first release run (#368).

windows-msvc.yml / windows-2025-vs2026 · MSVC amd64 hardened fails to build: 38 error C4996 across the suite:

  • _wfopen (20, tests/support/capture.hpp);
  • wcstok, gmtime, wcsrtombs, strncpy, sscanf, wcsncpy, strtok, strncat, fopen.

/sdl turns the CRT's deprecation warning C4996 into an error. Its suggested replacements are the _s functions (C11 Annex K), which no other standard library here ships. The tests check standard C and C++ functions, so they must keep calling them.

Fix: when the hardened build uses /sdl, also define _CRT_SECURE_NO_WARNINGS, Microsoft's switch for this warning. /sdl's runtime checks and its other warnings-as-errors stay. docs/security/hardening.md says so where it describes /sdl.

Activity

  1. self-assigned this
    on Nov 3, 2026
  2. homer6 commented on Nov 3, 2026

    @homer6
    OwnerAuthor

    Delivered in #383.

    What changed

    • tests/CMakeLists.txt defines _CRT_SECURE_NO_WARNINGS when the hardened build uses /sdl. hardening.md explains it, and notes that glibc has no Annex K (checked: glibc 2.41).

    Why

    • /sdl turned C4996 on standard functions into 38 build errors. Only that warning is silenced; /sdl's other checks stay.

    Still open

    • MSVC can't run locally: proof is the hardened MSVC job re-run.
  3. homer6 commented on Nov 3, 2026

    @homer6
    OwnerAuthor

    Merged in #383 (7b4c54b).

    What changed

    • Nothing since the PR was opened: no follow-up commits and no rebase.

    Why

    • Merged on the owner's review.

    Still open

  4. homer6 commented on Nov 3, 2026

    @homer6
    OwnerAuthor

    Reopened: #383 is incomplete. Processing the run's full digest found one C4996 that _CRT_SECURE_NO_WARNINGS doesn't cover: tests/language/declarations-initialization/attributes_test.cpp(87) calls its own [[deprecated("use new_api()")]] old_api() on purpose, and only #pragma GCC diagnostic silences it, which MSVC ignores (C4068). Under /sdl that warning is an error too. A follow-up PR adds the MSVC equivalent (#pragma warning(disable: 4996) around the call).

  5. reopened this on Nov 3, 2026
  6. homer6 commented on Nov 3, 2026

    @homer6
    OwnerAuthor

    Delivered in #386, together with #383.

    What changed

    • attributes_test.cpp: MSVC gets #pragma warning(disable : 4996) around the deliberate [[deprecated]] call.

    Why

    • It was the last C4996 in the hardened MSVC job that _CRT_SECURE_NO_WARNINGS doesn't cover. Attributes tests pass on gcc-15 and clang-22.

    Still open

    • MSVC proof: the hardened MSVC job re-run.
  7. homer6 commented on Nov 3, 2026

    @homer6
    OwnerAuthor

    Merged in #386 (86f6c76), after #383.

    What changed

    • Nothing since the PR was opened.

    Why

    • Merged on the owner's review.

    Still open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions