@@ -21,11 +21,16 @@ import cpptrace;
2121#endif
2222
2323
24+ static volatile int truthy = 2 ;
25+
2426namespace {
2527 template <typename E, typename ... Args>
2628 CPPTRACE_FORCE_NO_INLINE
27- void do_throw (Args&&... args) {
28- throw E (std::forward<Args>(args)...);
29+ int do_throw (Args&&... args) {
30+ if (truthy) {
31+ throw E (std::forward<Args>(args)...);
32+ }
33+ return 2 ;
2934 }
3035
3136 void check_trace (const cpptrace::stacktrace& trace, std::string file, int line) {
@@ -74,7 +79,8 @@ TEST(TryCatch, Basic) {
7479 cpptrace::try_catch (
7580 [&] {
7681 line = __LINE__ + 1 ;
77- do_throw<std::runtime_error>(" foobar" );
82+ volatile int x = do_throw<std::runtime_error>(" foobar" );
83+ (void )x;
7884 },
7985 [&] (const std::runtime_error& e) {
8086 did_catch = true ;
@@ -106,7 +112,8 @@ TEST(TryCatch, Upcast) {
106112 cpptrace::try_catch (
107113 [&] {
108114 line = __LINE__ + 1 ;
109- do_throw<std::runtime_error>(" foobar" );
115+ volatile int x = do_throw<std::runtime_error>(" foobar" );
116+ (void )x;
110117 },
111118 [&] (const std::exception& e) {
112119 did_catch = true ;
@@ -125,7 +132,8 @@ TEST(TryCatch, NoHandler) {
125132 cpptrace::try_catch (
126133 [&] {
127134 line = __LINE__ + 1 ;
128- do_throw<std::exception>();
135+ volatile int x = do_throw<std::exception>();
136+ (void )x;
129137 },
130138 [&] (const std::runtime_error&) {
131139 FAIL ();
@@ -145,7 +153,8 @@ TEST(TryCatch, NoMatchingHandler) {
145153 cpptrace::try_catch (
146154 [&] {
147155 line = __LINE__ + 1 ;
148- do_throw<std::exception>();
156+ volatile int x = do_throw<std::exception>();
157+ (void )x;
149158 }
150159 );
151160 FAIL ();
@@ -162,7 +171,8 @@ TEST(TryCatch, CorrectHandler) {
162171 cpptrace::try_catch (
163172 [&] {
164173 line = __LINE__ + 1 ;
165- do_throw<std::runtime_error>(" foobar" );
174+ volatile int x = do_throw<std::runtime_error>(" foobar" );
175+ (void )x;
166176 },
167177 [&] (int ) {
168178 FAIL ();
@@ -190,7 +200,8 @@ TEST(TryCatch, BlanketHandler) {
190200 cpptrace::try_catch (
191201 [&] {
192202 line = __LINE__ + 1 ;
193- do_throw<std::exception>();
203+ volatile int x = do_throw<std::exception>();
204+ (void )x;
194205 },
195206 [&] (int ) {
196207 FAIL ();
@@ -217,7 +228,8 @@ TEST(TryCatch, CatchOrdering) {
217228 cpptrace::try_catch (
218229 [&] {
219230 line = __LINE__ + 1 ;
220- do_throw<std::runtime_error>(" foobar" );
231+ volatile int x = do_throw<std::runtime_error>(" foobar" );
232+ (void )x;
221233 },
222234 [&] (int ) {
223235 FAIL ();
@@ -270,7 +282,8 @@ TEST(TryCatch, Value) {
270282 copy_move_tracker::reset ();
271283 cpptrace::try_catch (
272284 [&] {
273- do_throw<copy_move_tracker>();
285+ volatile int x = do_throw<copy_move_tracker>();
286+ (void )x;
274287 },
275288 [&] (copy_move_tracker) {
276289 did_catch = true ;
@@ -286,7 +299,8 @@ TEST(TryCatch, Ref) {
286299 copy_move_tracker::reset ();
287300 cpptrace::try_catch (
288301 [&] {
289- do_throw<copy_move_tracker>();
302+ volatile int x = do_throw<copy_move_tracker>();
303+ (void )x;
290304 },
291305 [&] (copy_move_tracker&) {
292306 did_catch = true ;
@@ -302,7 +316,8 @@ TEST(TryCatch, ConstRef) {
302316 copy_move_tracker::reset ();
303317 cpptrace::try_catch (
304318 [&] {
305- do_throw<copy_move_tracker>();
319+ volatile int x = do_throw<copy_move_tracker>();
320+ (void )x;
306321 },
307322 [&] (const copy_move_tracker&) {
308323 did_catch = true ;
0 commit comments