Kaynağa Gözat

Maybe_unused Attribute used instead of casts to void for marking unused

variables (fixes #118).
main
offa 6 yıl önce
ebeveyn
işleme
64d50e271c
4 değiştirilmiş dosya ile 29 ekleme ve 57 silme
  1. +5
    -10
      test/ScopeExitTest.cpp
  2. +7
    -14
      test/ScopeFailTest.cpp
  3. +8
    -15
      test/ScopeSuccessTest.cpp
  4. +9
    -18
      test/UniqueResourceTest.cpp

+ 5
- 10
test/ScopeExitTest.cpp Dosyayı Görüntüle

@@ -39,16 +39,14 @@ namespace
TEST_CASE("exit function called on destruction", "[ScopeExit]")
{
REQUIRE_CALL(m, deleter());
auto guard = sr::scope_exit{deleter};
static_cast<void>(guard);
[[maybe_unused]] auto guard = sr::scope_exit{deleter};
}

TEST_CASE("exit function lambda called on destruction", "[ScopeExit]")
{
CallMock cm;
REQUIRE_CALL(cm, deleter());
auto guard = sr::scope_exit{[&cm] { cm.deleter(); }};
static_cast<void>(guard);
[[maybe_unused]] auto guard = sr::scope_exit{[&cm] { cm.deleter(); }};
}

TEST_CASE("exit function called and rethrow on copy exception", "[ScopeExit]")
@@ -72,8 +70,7 @@ TEST_CASE("move releases moved-from object", "[ScopeExit]")
{
REQUIRE_CALL(m, deleter());
auto movedFrom = sr::scope_exit{deleter};
auto guard = std::move(movedFrom);
static_cast<void>(guard);
[[maybe_unused]] auto guard = std::move(movedFrom);
}

TEST_CASE("move with copy init releases moved-from object", "[ScopeExit]")
@@ -89,8 +86,7 @@ TEST_CASE("move transfers state", "[ScopeExit]")
{
REQUIRE_CALL(m, deleter());
auto movedFrom = sr::scope_exit{deleter};
auto guard = std::move(movedFrom);
static_cast<void>(guard);
[[maybe_unused]] auto guard = std::move(movedFrom);
}

TEST_CASE("move transfers state if released", "[ScopeExit]")
@@ -98,7 +94,6 @@ TEST_CASE("move transfers state if released", "[ScopeExit]")
REQUIRE_CALL(m, deleter()).TIMES(0);
auto movedFrom = sr::scope_exit{deleter};
movedFrom.release();
auto guard = std::move(movedFrom);
static_cast<void>(guard);
[[maybe_unused]] auto guard = std::move(movedFrom);
}


+ 7
- 14
test/ScopeFailTest.cpp Dosyayı Görüntüle

@@ -39,16 +39,14 @@ namespace
TEST_CASE("exit function called on destruction", "[ScopeFail]")
{
REQUIRE_CALL(m, deleter()).TIMES(0);
auto guard = sr::scope_fail{deleter};
static_cast<void>(guard);
[[maybe_unused]] auto guard = sr::scope_fail{deleter};
}

TEST_CASE("exit function lambda called on destruction", "[ScopeFail]")
{
CallMock cm;
REQUIRE_CALL(cm, deleter()).TIMES(0);
auto guard = sr::scope_fail{[&cm] { cm.deleter(); }};
static_cast<void>(guard);
[[maybe_unused]] auto guard = sr::scope_fail{[&cm] { cm.deleter(); }};
}

TEST_CASE("exit function called and rethrow on copy exception", "[ScopeFail]")
@@ -72,8 +70,7 @@ TEST_CASE("move releases moved-from object", "[ScopeFail]")
{
REQUIRE_CALL(m, deleter()).TIMES(0);
auto movedFrom = sr::scope_fail{deleter};
auto guard = std::move(movedFrom);
static_cast<void>(guard);
[[maybe_unused]] auto guard = std::move(movedFrom);
}

TEST_CASE("move with copy init releases moved-from object", "[ScopeFail]")
@@ -89,8 +86,7 @@ TEST_CASE("move transfers state", "[ScopeFail]")
{
REQUIRE_CALL(m, deleter()).TIMES(0);
auto movedFrom = sr::scope_fail{deleter};
auto guard = std::move(movedFrom);
static_cast<void>(guard);
[[maybe_unused]] auto guard = std::move(movedFrom);
}

TEST_CASE("move transfers state if released", "[ScopeFail]")
@@ -98,8 +94,7 @@ TEST_CASE("move transfers state if released", "[ScopeFail]")
REQUIRE_CALL(m, deleter()).TIMES(0);
auto movedFrom = sr::scope_fail{deleter};
movedFrom.release();
auto guard = std::move(movedFrom);
static_cast<void>(guard);
[[maybe_unused]] auto guard = std::move(movedFrom);
}

TEST_CASE("exit function called on exception", "[ScopeFail]")
@@ -107,8 +102,7 @@ TEST_CASE("exit function called on exception", "[ScopeFail]")
try
{
REQUIRE_CALL(m, deleter());
auto guard = sr::scope_fail{deleter};
static_cast<void>(guard);
[[maybe_unused]] auto guard = sr::scope_fail{deleter};
throw 3;
}
catch( ... )
@@ -124,8 +118,7 @@ TEST_CASE("exit function not called on pending exception", "[ScopeFail]")
}
catch( ... )
{
auto guard = sr::scope_fail{deleter};
static_cast<void>(guard);
[[maybe_unused]] auto guard = sr::scope_fail{deleter};
}
}


+ 8
- 15
test/ScopeSuccessTest.cpp Dosyayı Görüntüle

@@ -39,16 +39,14 @@ namespace
TEST_CASE("exit function called on destruction", "[ScopeSuccess]")
{
REQUIRE_CALL(m, deleter());
auto guard = sr::scope_success{deleter};
static_cast<void>(guard);
[[maybe_unused]] auto guard = sr::scope_success{deleter};
}

TEST_CASE("exit function lambda called on destruction", "[ScopeSuccess]")
{
CallMock cm;
REQUIRE_CALL(cm, deleter());
auto guard = sr::scope_success{[&cm] { cm.deleter(); }};
static_cast<void>(guard);
[[maybe_unused]] auto guard = sr::scope_success{[&cm] { cm.deleter(); }};
}

TEST_CASE("exit function not called and rethrow on copy exception", "[ScopeSuccess]")
@@ -71,8 +69,7 @@ TEST_CASE("move releases moved-from object", "[ScopeSuccess]")
{
REQUIRE_CALL(m, deleter());
auto movedFrom = sr::scope_success{deleter};
auto guard = std::move(movedFrom);
static_cast<void>(guard);
[[maybe_unused]] auto guard = std::move(movedFrom);
}

TEST_CASE("move with copy init releases moved-from object", "[ScopeSuccess]")
@@ -81,15 +78,14 @@ TEST_CASE("move with copy init releases moved-from object", "[ScopeSuccess]")
const NotNothrowMoveMock notNothrow{&mock};
REQUIRE_CALL(mock, deleter());
sr::scope_success movedFrom{notNothrow};
auto guard = std::move(movedFrom);
[[maybe_unused]] auto guard = std::move(movedFrom);
}

TEST_CASE("move transfers state", "[ScopeSuccess]")
{
REQUIRE_CALL(m, deleter());
auto movedFrom = sr::scope_success{deleter};
auto guard = std::move(movedFrom);
static_cast<void>(guard);
[[maybe_unused]] auto guard = std::move(movedFrom);
}

TEST_CASE("move transfers state if released", "[ScopeSuccess]")
@@ -97,16 +93,14 @@ TEST_CASE("move transfers state if released", "[ScopeSuccess]")
REQUIRE_CALL(m, deleter()).TIMES(0);
auto movedFrom = sr::scope_success{deleter};
movedFrom.release();
auto guard = std::move(movedFrom);
static_cast<void>(guard);
[[maybe_unused]] auto guard = std::move(movedFrom);
}

TEST_CASE("exit function not called on exception", "[ScopeFail]")
{
try
{
auto guard = sr::scope_success{deleter};
static_cast<void>(guard);
[[maybe_unused]] auto guard = sr::scope_success{deleter};
throw 3;
}
catch( ... )
@@ -123,8 +117,7 @@ TEST_CASE("exit function called on pending exception", "[ScopeFail]")
catch( ... )
{
REQUIRE_CALL(m, deleter());
auto guard = sr::scope_success{deleter};
static_cast<void>(guard);
[[maybe_unused]] auto guard = sr::scope_success{deleter};
}
}


+ 9
- 18
test/UniqueResourceTest.cpp Dosyayı Görüntüle

@@ -39,8 +39,7 @@ namespace
TEST_CASE("construction with move", "[UniqueResource]")
{
REQUIRE_CALL(m, deleter(3));
auto guard = sr::unique_resource{Handle{3}, deleter};
static_cast<void>(guard);
[[maybe_unused]] auto guard = sr::unique_resource{Handle{3}, deleter};
}

TEST_CASE("construction with copy", "[UniqueResource]")
@@ -48,8 +47,7 @@ TEST_CASE("construction with copy", "[UniqueResource]")
REQUIRE_CALL(m, deleter(3));
const Handle h{3};
const auto d = [](auto v) { m.deleter(v); };
auto guard = sr::unique_resource{h, d};
static_cast<void>(guard);
[[maybe_unused]] auto guard = sr::unique_resource{h, d};
}

TEST_CASE("construction with copy calls deleter and rethrows on failed copy", "[UniqueResource]")
@@ -59,8 +57,7 @@ TEST_CASE("construction with copy calls deleter and rethrows on failed copy", "[
const auto d = [](const auto&) { m.deleter(3); };
REQUIRE_CALL(m, deleter(3));

sr::unique_resource guard{noMove, d};
static_cast<void>(guard);
[[maybe_unused]] sr::unique_resource guard{noMove, d};
}());
}

@@ -79,8 +76,7 @@ TEST_CASE("move-construction with copy", "[UniqueResource]")

const CopyMock copyMock;
sr::unique_resource movedFrom{copyMock, d};
auto guard = std::move(movedFrom);
static_cast<void>(guard);
[[maybe_unused]] auto guard = std::move(movedFrom);
}

TEST_CASE("move assignment calls deleter", "[UniqueResource]")
@@ -98,8 +94,7 @@ TEST_CASE("move assignment calls deleter", "[UniqueResource]")
TEST_CASE("deleter called on destruction", "[UniqueResource]")
{
REQUIRE_CALL(m, deleter(3));
auto guard = sr::unique_resource{Handle{3}, deleter};
static_cast<void>(guard);
[[maybe_unused]] auto guard = sr::unique_resource{Handle{3}, deleter};
}

TEST_CASE("reset calls deleter", "[UniqueResource]")
@@ -190,28 +185,24 @@ TEST_CASE("deleter access", "[UniqueResource]")
TEST_CASE("make unique resource", "[UniqueResource]")
{
REQUIRE_CALL(m, deleter(7));
auto guard = sr::unique_resource{Handle{7}, deleter};
static_cast<void>(guard);
[[maybe_unused]] auto guard = sr::unique_resource{Handle{7}, deleter};
}

TEST_CASE("make unique resource with reference wrapper", "[UniqueResource]")
{
REQUIRE_CALL(m, deleter(3));
Handle h{3};
auto guard = sr::unique_resource{std::ref(h), deleter};
static_cast<void>(guard);
[[maybe_unused]] auto guard = sr::unique_resource{std::ref(h), deleter};
}

TEST_CASE("make unique resource checked", "[UniqueResource]")
{
REQUIRE_CALL(m, deleter(4));
auto guard = sr::make_unique_resource_checked(Handle{4}, Handle{-1}, deleter);
static_cast<void>(guard);
[[maybe_unused]] auto guard = sr::make_unique_resource_checked(Handle{4}, Handle{-1}, deleter);
}

TEST_CASE("make unique resource checked releases if invalid", "[UniqueResource]")
{
auto guard = sr::make_unique_resource_checked(Handle{-1}, Handle{-1}, deleter);
static_cast<void>(guard);
[[maybe_unused]] auto guard = sr::make_unique_resource_checked(Handle{-1}, Handle{-1}, deleter);
}


Yükleniyor…
İptal
Kaydet