Skip to content

__builtin_unreachable ( ) on Windows #45

@degski

Description

@degski

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>;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions