Skip to content

syserror.cpp: update _Syserror_map#2742

Merged
StephanTLavavej merged 2 commits into
microsoft:mainfrom
fsb4000:fix2561
Jul 1, 2022
Merged

syserror.cpp: update _Syserror_map#2742
StephanTLavavej merged 2 commits into
microsoft:mainfrom
fsb4000:fix2561

Conversation

@fsb4000
Copy link
Copy Markdown
Contributor

@fsb4000 fsb4000 commented May 26, 2022

Fixes #2561

This PR affects redist.

It is expected that the fix can be included in VS 2022 17.4 Preview 2.

The changes is tested via:

// Also test LWG-3598: system_category().default_error_condition(0) has a generic category.
void test_lwg_3598() {
error_condition cond = system_category().default_error_condition(0);
assert(cond.category() == generic_category());
assert(cond.message() == "success");
assert(cond.value() == 0);
assert(error_code() == error_condition());
}

@fsb4000 fsb4000 requested a review from a team as a code owner May 26, 2022 15:37
@CaseyCarter CaseyCarter added enhancement Something can be improved affects redist labels May 26, 2022
Comment thread stl/src/syserror.cpp Outdated
@CaseyCarter CaseyCarter added the blocked Something is preventing work on this label May 26, 2022
@CaseyCarter
Copy link
Copy Markdown
Contributor

For clarity: I'm tagging this "blocked" since it depends on a runtime update for correctness. As fsb4000 says in the OP, we'll merge this for 17.4 when the redist is unlocked.

@StephanTLavavej
Copy link
Copy Markdown
Member

Note that this affects the behavior of future_category and iostream_category.

D:\GitHub\STL\out\build\x64>type meow.cpp
#include <future>
#include <iostream>
#include <system_error>
using namespace std;

int main() {
    cout << "future_category: " << error_code{0, future_category()}.message() << "\n";
    cout << "generic_category: " << error_code{0, generic_category()}.message() << "\n";
    cout << "iostream_category: " << error_code{0, iostream_category()}.message() << "\n";
    cout << "system_category: " << error_code{0, system_category()}.message() << "\n";
}
D:\GitHub\STL\out\build\x64>cl /EHsc /nologo /W4 /MTd meow.cpp
meow.cpp

Before #2560:

future_category: unknown error
generic_category: unknown error
iostream_category: unknown error
system_category: The operation completed successfully.

With #2560 (shipped in VS 2022 17.2):

future_category: unknown error
generic_category: success
iostream_category: unknown error
system_category: The operation completed successfully.

This PR:

future_category: success
generic_category: success
iostream_category: success
system_category: The operation completed successfully.

This seems reasonable to me, as future_errc and io_errc use nonzero error codes:

STL/stl/inc/future

Lines 63 to 68 in 60decd0

enum class future_errc { // names for futures errors
broken_promise = 1,
future_already_retrieved,
promise_already_satisfied,
no_state
};

STL/stl/inc/system_error

Lines 33 to 35 in 60decd0

enum class io_errc { // error codes for ios_base::failure
stream = 1
};

@CaseyCarter
Copy link
Copy Markdown
Contributor

This seems reasonable to me, as future_errc and io_errc use nonzero error codes

The fact that error_code and error_condition have an operator bool that returns value() != 0 effectively means that meow{0} must represent success for every is_error_code_enum / is_error_condition_enum type meow. If anything, I'd call this an improvement.

@StephanTLavavej
Copy link
Copy Markdown
Member

Confirming that this is blocked - at this time, we aren't certain whether code is flowing into 17.4 Preview 1 (locked) or Preview 2 (unlocked). Moving to cryo-stasis for now.

@StephanTLavavej StephanTLavavej removed the blocked Something is preventing work on this label Jun 29, 2022
@StephanTLavavej StephanTLavavej self-assigned this Jun 30, 2022
@StephanTLavavej
Copy link
Copy Markdown
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit 600f257 into microsoft:main Jul 1, 2022
@StephanTLavavej
Copy link
Copy Markdown
Member

Thanks for cleaning up this code and improving the behavior of the error categories! 🧹 🚀 😸

@fsb4000 fsb4000 deleted the fix2561 branch July 1, 2022 04:12
fsb4000 added a commit to fsb4000/STL that referenced this pull request Aug 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Something can be improved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

syserror.cpp: update _Syserror_map

3 participants