Skip to content

<utility>: make unreachable() call the doom function in debug mode - #6159

Merged
Stephan T. Lavavej (StephanTLavavej) merged 7 commits into
microsoft:mainfrom
AlexGuteniev:failsafe
Mar 31, 2026
Merged

<utility>: make unreachable() call the doom function in debug mode#6159
Stephan T. Lavavej (StephanTLavavej) merged 7 commits into
microsoft:mainfrom
AlexGuteniev:failsafe

Conversation

@AlexGuteniev

@AlexGuteniev Alex Guteniev (AlexGuteniev) commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

Fix #6151.

In debug mode, unreachable() will deterministically call the doom function. In release mode, users get the UB they asked for.

Extract doom function to a new core header to achieve that. As A. Jiang (@frederick-vs-ja) suggested, core headers do call some functions. In this case, a function will be called by default for /clr configurations only.

Extended test coverage to make sure the machinery does not break compilation.
No runtime coverage -- it is still UB to call unreachable() according to the Standard.

Comment thread stl/inc/header-units.json Outdated
Comment thread stl/inc/utility Outdated
Comment thread stl/inc/utility Outdated
Comment thread tests/std/tests/P0627R6_unreachable/test.cpp Outdated
Comment thread tests/std/tests/P0627R6_unreachable/test.cpp Outdated
@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) added the enhancement Something can be improved label Mar 14, 2026
@fortsnek9348

Copy link
Copy Markdown

Yes, this just tripped me up. I used std::unreachable assuming the debug build will check it. But finding out that it doesn't, I may just have to never ever use the function. No debug checks at all is too dangerous for me.

@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) changed the title <utility>: attempt to call doom function on unreachable() call in a debug configuration <utility>: make unreachable() call the doom function in debug mode Mar 31, 2026
Comment thread tests/std/tests/GH_001411_core_headers/test.cpp
Comment thread tests/std/tests/GH_001411_core_headers/test.cpp
@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) moved this from Initial Review to Ready To Merge in STL Code Reviews Mar 31, 2026
@StephanTLavavej

Copy link
Copy Markdown
Member

I'm mirroring this to the MSVC-internal repo. Please notify me if any further changes are pushed, otherwise no action is required.

@StephanTLavavej Stephan T. Lavavej (StephanTLavavej) moved this from Ready To Merge to Merging in STL Code Reviews Mar 31, 2026
@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit a393a18 into microsoft:main Mar 31, 2026
49 checks passed
@github-project-automation github-project-automation Bot moved this from Merging to Done in STL Code Reviews Mar 31, 2026
@StephanTLavavej

Copy link
Copy Markdown
Member

🦹‍♂️ ☠️ 🪲

@K-ballo

Copy link
Copy Markdown

Alex Guteniev (@AlexGuteniev) thanks again for your work! 🎉

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.

<utility>: unreachable does not abort in debug builds

4 participants