Search code examples
c++visual-studiovisual-c++c++17visual-studio-2019

Emulating GCC's __builtin_unreachable in Visual Studio?


I have seen this question which is about emulating __builtin_unreachable in an older version of GCC. My question is exactly that, but for Visual Studio (2019). Does Visual Studio have some equivalent of __builtin_unreachable? Is it possible to emulate it?


Solution

  • MSVC has the __assume builtin which can be used to implement __builtin_unreachable. As the documentation says, __assume(0) must not be in a reachable branch of code, which means, that branch must be unreachable.