Skip to content

Commit

Permalink
test/thread_ctor_throw: New test
Browse files Browse the repository at this point in the history
  • Loading branch information
lhmouse committed Sep 24, 2024
1 parent 5812f42 commit 196a025
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ test_src = [
'test/thread_move_assign_terminate.cpp',
'test/thread_move_assign_joined.cpp',
'test/thread_join_deadlock.cpp',
'test/thread_ctor_throw.cpp',
'test/thread_id.cpp',
'test/thread_decay_copy.cpp',
'test/this_thread_sleep_until.cpp',
Expand Down
39 changes: 39 additions & 0 deletions test/thread_ctor_throw.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* This file is part of MCF Gthread.
* Copyright (C) 2022-2024 LH_Mouse. All wrongs reserved.
*
* MCF Gthread is free software. Licensing information is included in
* LICENSE.TXT as a whole. The GCC Runtime Library Exception applies
* to this file. */

#include "../mcfgthread/cxx11.hpp"
#include "../mcfgthread/exit.h"
#include <assert.h>
#include <stdio.h>

#ifdef TEST_STD
# include <thread>
namespace NS = std;
#else
namespace NS = ::_MCF;
#endif

struct copy_will_throw
{
copy_will_throw() { }
copy_will_throw(const copy_will_throw&) { throw 42; }
void operator()() { ::std::terminate(); }
};

int
main(void)
{
try {
copy_will_throw t;
NS::thread thr(t);
::std::terminate();
}
catch(int e) {
NS::this_thread::sleep_for(NS::chrono::seconds(3));
assert(e == 42);
}
}

0 comments on commit 196a025

Please sign in to comment.