Files
tdesktop/cmake/external/glib/cppgir/expected-lite/example/03-no-exceptions.cpp
allhaileris afb81b8278
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
init
2026-02-16 15:50:16 +03:00

78 lines
1.8 KiB
C++

// Copyright (c) 2016-2020 Martin Moene
//
// https://github.com/martinmoene/expected-lite
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include "nonstd/expected.hpp"
#include <iostream>
template< typename T >
void use( T const & /*x*/) {}
#define expected_PRESENT( x ) \
std::cout << #x << ": " << x << "\n"
#define expected_ABSENT( x ) \
std::cout << #x << ": (undefined)\n"
void report()
{
#ifdef __cpp_exceptions
expected_PRESENT( __cpp_exceptions );
#else
expected_ABSENT( __cpp_exceptions );
#endif
#ifdef __EXCEPTIONS
expected_PRESENT( __EXCEPTIONS );
#else
expected_ABSENT( __EXCEPTIONS );
#endif
#ifdef _HAS_EXCEPTIONS
expected_PRESENT( _HAS_EXCEPTIONS );
#else
expected_ABSENT( _HAS_EXCEPTIONS );
#endif
#ifdef _CPPUNWIND
expected_PRESENT( _CPPUNWIND );
#else
expected_ABSENT( _CPPUNWIND );
#endif
}
int violate_access()
{
nonstd::expected<int, char> eu( nonstd:: make_unexpected('a') );
return eu.value();
}
int main()
{
report();
#if ! nsel_CONFIG_NO_EXCEPTIONS_SEH
return violate_access();
#else
__try
{
return violate_access();
}
__except( EXCEPTION_EXECUTE_HANDLER )
{
std::cerr << "\n*** Executing SEH __except block ***\n";
}
#endif
}
// -Dnsel_CONFIG_NO_EXCEPTIONS=1 automatically determined in expected.hpp
// -Dnsel_CONFIG_NO_EXCEPTIONS_SEH=0 default:1 for msvc
// cl -nologo -kernel -EHs-c- -GR- -I../include 03-no-exceptions.cpp && 03-no-exceptions
// cl -nologo -kernel -EHs-c- -GR- -Dnsel_CONFIG_NO_EXCEPTIONS_SEH=0 -I../include 03-no-exceptions.cpp && 03-no-exceptions
// g++ -Wall -fno-exceptions -I../include -o 03-no-exceptions 03-no-exceptions.cpp && 03-no-exceptions