1// Copyright 2022 Peter Dimov
2// Distributed under the Boost Software License, Version 1.0.
3// http://www.boost.org/LICENSE_1_0.txt
4
5// Reduced from a boost::system::result test; codegen bug
6// in GCC < 5 which is somehow triggered by __PRETTY_FUNCTION__
7// and throwing an exception
8
9#include <boost/assert/source_location.hpp>
10#include <boost/core/lightweight_test.hpp>
11#include <exception>
12
13template<class T> class result
14{
15private:
16
17 bool has_value_;
18 T value_;
19
20public:
21
22 result(): has_value_( false ), value_()
23 {
24 }
25
26 T value( boost::source_location const& /*loc*/ = BOOST_CURRENT_LOCATION ) const
27 {
28 if( has_value_ )
29 {
30 return value_;
31 }
32 else
33 {
34 throw std::exception();
35 }
36 }
37};
38
39int main()
40{
41 result<int> r;
42 BOOST_TEST_THROWS( r.value(), std::exception );
43 return boost::report_errors();
44}
45

source code of boost/libs/assert/test/source_location_test5.cpp