`<utility>`: make `unreachable()` call the doom function in debug mode by AlexGuteniev · Pull Request #6159 · microsoft/STL · GitHub
Skip to content

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

Merged
StephanTLavavej merged 7 commits into
microsoft:mainfrom
AlexGuteniev:failsafe
Mar 31, 2026
Merged

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

Conversation

@AlexGuteniev

@AlexGuteniev 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 @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.

@AlexGuteniev AlexGuteniev requested a review from a team as a code owner March 14, 2026 08:17
@github-project-automation github-project-automation Bot moved this to Initial Review in STL Code Reviews Mar 14, 2026
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 StephanTLavavej added the enhancement Something can be improved label Mar 14, 2026
@fortsnek9348

Copy link
Copy Markdown

@StephanTLavavej StephanTLavavej self-assigned this Mar 29, 2026
@StephanTLavavej 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 StephanTLavavej removed their assignment Mar 31, 2026
@StephanTLavavej 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 StephanTLavavej moved this from Ready To Merge to Merging in STL Code Reviews Mar 31, 2026
@StephanTLavavej 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

K-ballo commented Apr 1, 2026

Copy link
Copy Markdown

@AlexGuteniev AlexGuteniev deleted the failsafe branch April 1, 2026 06:05
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

Archived in project

Development

Successfully merging this pull request may close these issues.

<utility>: unreachable does not abort in debug builds

4 participants