• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2015 Microsoft Corporation. All rights reserved.
4 //
5 // This code is licensed under the MIT License (MIT).
6 //
7 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
8 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
10 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
11 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
12 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
13 // THE SOFTWARE.
14 //
15 ///////////////////////////////////////////////////////////////////////////////
16 
17 #include <cstdlib>        // for std::exit
18 #include <gsl/gsl_assert> // for get_terminate
19 #include <gsl/gsl_util>   // for narrow
20 
narrow_no_throw()21 int narrow_no_throw()
22 {
23     const long long bigNumber = 0x0fffffffffffffff;
24     return gsl::narrow<int>(bigNumber);
25 }
26 
test_terminate()27 [[noreturn]] void test_terminate() { std::exit(0); }
28 
setup_termination_handler()29 void setup_termination_handler() noexcept
30 {
31 #if defined(_MSC_VER)
32 
33     auto& handler = gsl::details::get_terminate_handler();
34     handler = &test_terminate;
35 
36 #else
37 
38     std::set_terminate(test_terminate);
39 
40 #endif
41 }
42 
main()43 int main()
44 {
45     setup_termination_handler();
46     narrow_no_throw();
47     return -1;
48 }
49