|
||||
File indexing completed on 2025-01-18 09:52:35
0001 #ifndef BOOST_SYSTEM_DETAIL_THROWS_HPP_INCLUDED 0002 #define BOOST_SYSTEM_DETAIL_THROWS_HPP_INCLUDED 0003 0004 // Copyright Beman Dawes 2006, 2007 0005 // Copyright Christoper Kohlhoff 2007 0006 // Copyright Peter Dimov 2017, 2018 0007 // 0008 // Distributed under the Boost Software License, Version 1.0. (See accompanying 0009 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 0010 // 0011 // See library home page at http://www.boost.org/libs/system 0012 0013 namespace boost 0014 { 0015 0016 namespace system 0017 { 0018 0019 class error_code; 0020 0021 } // namespace system 0022 0023 // boost::throws() 0024 0025 namespace detail 0026 { 0027 0028 // Misuse of the error_code object is turned into a noisy failure by 0029 // poisoning the reference. This particular implementation doesn't 0030 // produce warnings or errors from popular compilers, is very efficient 0031 // (as determined by inspecting generated code), and does not suffer 0032 // from order of initialization problems. In practice, it also seems 0033 // cause user function error handling implementation errors to be detected 0034 // very early in the development cycle. 0035 0036 inline system::error_code* throws() 0037 { 0038 // See github.com/boostorg/system/pull/12 by visigoth for why the return 0039 // is poisoned with nonzero rather than (0). A test, test_throws_usage(), 0040 // has been added to error_code_test.cpp, and as visigoth mentioned it 0041 // fails on clang for release builds with a return of 0 but works fine 0042 // with (1). 0043 // Since the undefined behavior sanitizer (-fsanitize=undefined) does not 0044 // allow a reference to be formed to the unaligned address of (1), we use 0045 // (8) instead. 0046 0047 return reinterpret_cast<system::error_code*>(8); 0048 } 0049 0050 } // namespace detail 0051 0052 inline system::error_code& throws() 0053 { 0054 return *detail::throws(); 0055 } 0056 0057 } // namespace boost 0058 0059 #endif // #ifndef BOOST_SYSTEM_DETAIL_THROWS_HPP_INCLUDED
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |