Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__builtin_unreachable ( ) on Windows #45

Open
degski opened this issue Feb 11, 2020 · 1 comment
Open

__builtin_unreachable ( ) on Windows #45

degski opened this issue Feb 11, 2020 · 1 comment

Comments

@degski
Copy link

degski commented Feb 11, 2020

On Windows the function void __builtin_unreachable ( ) is undefined, and therefor the code is not functional with cl.exe. The below code snippet makes the code compile and does the 'right' thing:

#if defined( _WIN32 ) && !( defined( __clang__ ) || defined( __GNUC__ ) )
#pragma warning( disable : 4645 ) // suppress warning that non-returning function returns.
    [[noreturn]] static void __builtin_unreachable ( ) noexcept { return; /* intentional */ }
#pragma warning( default : 4645 )
#endif

Please add the above to master.

PS: I decided to wrap the library and fix the problem at the same time, also, as soon as C++20 is available, I can just delete the header and the STL will kick in automatically everywhere.

// MIT License
//
// Copyright (c) 2020 degski
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#pragma once

// <static_vector>

#if defined( _WIN32 ) && !( defined( __clang__ ) || defined( __GNUC__ ) )
#    pragma warning( disable : 4645 ) // suppress warning that non-returning function returns.
    [[noreturn]] static void __builtin_unreachable ( ) noexcept { return; /* intentional */ }
#    pragma warning( default : 4645 )
#endif

#include "experimental/fixed_capacity_vector"

namespace std {
    template<typename Type, std::size_t Size>
    using static_vector = experimental::fixed_capacity_vector<Type, Size>;
}
@degski degski changed the title __builtin_unreachable ( ) on **Windows** __builtin_unreachable ( ) on Windows Feb 11, 2020
@lethal-guitar
Copy link

@degski There is also __assume(false) for MSVC: lethal-guitar/RigelEngine@b99eb2d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants