Skip to content

Commit b484586

Browse files
committed
Fix wrong noexcept, improve testing.
1 parent 8c24770 commit b484586

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

include/tanuki/tanuki.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,7 @@ class TANUKI_VISIBLE wrap : private detail::wrap_storage<IFace, Cfg.static_size,
15271527
}
15281528

15291529
private:
1530-
void copy_init_from(const wrap &other) noexcept
1530+
void copy_init_from(const wrap &other)
15311531
{
15321532
static_assert(Cfg.semantics == wrap_semantics::value);
15331533

@@ -1860,8 +1860,7 @@ class TANUKI_VISIBLE wrap : private detail::wrap_storage<IFace, Cfg.static_size,
18601860
try {
18611861
w.template ctor_impl<T>(std::forward<Args>(args)...);
18621862
} catch (...) {
1863-
// NOTE: if ctor_impl fails there's no cleanup required.
1864-
// Invalidate this before rethrowing.
1863+
// NOTE: if ctor_impl fails there's no cleanup required, except to invalidate this before rethrowing.
18651864
w.m_pv_iface = nullptr;
18661865

18671866
throw;

test/test_basics.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,44 @@ TEST_CASE("assignment")
372372
}
373373
}
374374

375+
// NOTE: a small test to check the cleanup logic in the copy assignment operator of wrap when the assignment is
376+
// implemented via destroy + copy init and copy init throws.
377+
TEST_CASE("throwing copy assignment")
378+
{
379+
using tanuki::wrap;
380+
using wrap_t = wrap<any_iface>;
381+
382+
// NOLINTNEXTLINE
383+
struct throw_copy {
384+
throw_copy() = default;
385+
throw_copy(const throw_copy &)
386+
{
387+
throw std::invalid_argument("");
388+
}
389+
throw_copy(throw_copy &&) = default;
390+
throw_copy &operator=(const throw_copy &) = default;
391+
throw_copy &operator=(throw_copy &&) = default;
392+
};
393+
394+
{
395+
wrap_t w1(
396+
large{.str = "bsadsadasdsadsadsadsadsadsadsadasdkjsadkldjlsakdsjaljdklajdlksajdlkajdkljsakldjakllif"}),
397+
w2(throw_copy{});
398+
399+
REQUIRE_THROWS_AS((w1 = w2), std::invalid_argument);
400+
401+
REQUIRE(!is_valid(w1));
402+
}
403+
404+
{
405+
wrap_t w1(small{}), w2(throw_copy{});
406+
407+
REQUIRE_THROWS_AS((w1 = w2), std::invalid_argument);
408+
409+
REQUIRE(!is_valid(w1));
410+
}
411+
}
412+
375413
#if defined(TANUKI_WITH_BOOST_S11N)
376414

377415
TEST_CASE("s11n nostatic")

0 commit comments

Comments
 (0)