`<system_error>`: `system_category()` maps `WSAECONNREFUSED` etc. onto `errc`, but not their `winerror.h` equivalents (`ERROR_CONNECTION_REFUSED`, `ERROR_NETNAME_DELETED`, ...)

Open Beginner friendly
#6,471 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp

Research direction

Start in stl/src/syserror.cpp and inspect the _Win_errtab entries that map Winsock codes to portable errc conditions. Add coverage for the seven listed winerror.h codes, then run the repro.cpp checks or the relevant STL error-system tests and verify all 13 comparisons report true.

Written by the indexing model from the issue text.

Description

enhancement

Describe the bug

system_category().default_error_condition() maps the Winsock network error codes onto the portable errc
conditions, but not the winerror.h codes that Windows reports for the same failures. So whether
ec == errc::connection_refused holds for a refused connection depends on which API reported it.

The winerror.h codes are what overlapped I/O completions report: GetOverlappedResult /
GetQueuedCompletionStatus translate the NTSTATUS with the usual NTSTATUS-to-Win32 mapping, so a
ConnectEx to a closed port completes with ERROR_CONNECTION_REFUSED (not WSAECONNREFUSED), and a
reset connection completes a WSARecv with ERROR_NETNAME_DELETED (not WSAECONNRESET).

Missing from _Win_errtab (checked against main, stl/src/syserror.cpp):

winerror.h code Winsock equivalent, already mapped condition
ERROR_CONNECTION_REFUSED (1225) WSAECONNREFUSED connection_refused
ERROR_PORT_UNREACHABLE (1234) WSAECONNREFUSED connection_refused
ERROR_NETWORK_UNREACHABLE (1231) WSAENETUNREACH network_unreachable
ERROR_HOST_UNREACHABLE (1232) WSAEHOSTUNREACH host_unreachable
ERROR_CONNECTION_ABORTED (1236) WSAECONNABORTED connection_aborted
ERROR_NETNAME_DELETED (64) WSAECONNRESET connection_reset
ERROR_CANCELLED (1223) (ERROR_OPERATION_ABORTED) operation_canceled

Command-line test case

C:\Temp>type repro.cpp
#include <winsock2.h>
#include <windows.h>

#include <cstdio>
#include <system_error>
using namespace std;

void check(const char* name, int ev, const char* condName, errc cond) {
    printf("%-25s (%5d) == errc::%-19s : %s\n", name, ev, condName,
        error_code{ev, system_category()} == cond ? "true" : "false");
}
#define CHECK(ev, cond) check(#ev, ev, #cond, errc::cond)

int main() {
    CHECK(WSAECONNREFUSED, connection_refused);
    CHECK(ERROR_CONNECTION_REFUSED, connection_refused);
    CHECK(ERROR_PORT_UNREACHABLE, connection_refused);
    CHECK(WSAENETUNREACH, network_unreachable);
    CHECK(ERROR_NETWORK_UNREACHABLE, network_unreachable);
    CHECK(WSAEHOSTUNREACH, host_unreachable);
    CHECK(ERROR_HOST_UNREACHABLE, host_unreachable);
    CHECK(WSAECONNABORTED, connection_aborted);
    CHECK(ERROR_CONNECTION_ABORTED, connection_aborted);
    CHECK(WSAECONNRESET, connection_reset);
    CHECK(ERROR_NETNAME_DELETED, connection_reset);
    CHECK(ERROR_OPERATION_ABORTED, operation_canceled);
    CHECK(ERROR_CANCELLED, operation_canceled);
}

C:\Temp>cl /EHsc /W4 /WX /std:c++latest repro.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.51.36260 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

/std:c++latest is provided as a preview of language features from the latest C++
working draft, and we're eager to hear about bugs and suggestions for improvements.
However, note that these features are provided as-is without support, and subject
to changes or removal as the working draft evolves. See
https://go.microsoft.com/fwlink/?linkid=2045807 for details.

repro.cpp
Microsoft (R) Incremental Linker Version 14.51.36260.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:repro.exe
repro.obj

C:\Temp>repro.exe
WSAECONNREFUSED           (10061) == errc::connection_refused  : true
ERROR_CONNECTION_REFUSED  ( 1225) == errc::connection_refused  : false
ERROR_PORT_UNREACHABLE    ( 1234) == errc::connection_refused  : false
WSAENETUNREACH            (10051) == errc::network_unreachable : true
ERROR_NETWORK_UNREACHABLE ( 1231) == errc::network_unreachable : false
WSAEHOSTUNREACH           (10065) == errc::host_unreachable    : true
ERROR_HOST_UNREACHABLE    ( 1232) == errc::host_unreachable    : false
WSAECONNABORTED           (10053) == errc::connection_aborted  : true
ERROR_CONNECTION_ABORTED  ( 1236) == errc::connection_aborted  : false
WSAECONNRESET             (10054) == errc::connection_reset    : true
ERROR_NETNAME_DELETED     (   64) == errc::connection_reset    : false
ERROR_OPERATION_ABORTED   (  995) == errc::operation_canceled  : true
ERROR_CANCELLED           ( 1223) == errc::operation_canceled  : false

Expected behavior

Each winerror.h code compares equal to the same errc condition as its Winsock equivalent - all 13 lines true.

STL version

Microsoft Visual Studio Community 2026
Version 18.10.3

Also reproduced with VS 2022 17.14 (MSVC 14.44.35207). stl/src/syserror.cpp on main has none of these
seven codes.

Additional context

  • Boost.Asio works around exactly this, translating these codes by hand before reporting them
    (socket_ops.ipp):
    complete_iocp_connect maps ERROR_CONNECTION_REFUSED, ERROR_NETWORK_UNREACHABLE and ERROR_HOST_UNREACHABLE;
    complete_iocp_recv and recv map ERROR_NETNAME_DELETED -> connection_reset (and recv,
    ERROR_PORT_UNREACHABLE -> connection_refused). (complete_iocp_accept maps ERROR_NETNAME_DELETED to
    connection_aborted instead - for a connection reset before it was accepted - but connection_reset is what it
    means on an established connection, and what WSAECONNRESET already maps to.)
  • The same kind of gap as #2572 (WAIT_TIMEOUT vs errc::timed_out), fixed by #2744.
  • We hit this in Stroika, and now map these codes ourselves:
    https://github.com/SophistSolutions/Stroika/issues/1192
Dominant language
C++
Stars
11.2k
Forks
1.7k
Avg merge
4d 4h
Merged PRs (30d)
14

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/STL

All issues in microsoft/STL

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.