From: Joel Rosdahl Date: Fri, 8 May 2020 19:26:33 +0000 (+0200) Subject: Remove obsolete ScopeGuard X-Git-Tag: v4.0~469 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1fdd12e59f46b5428f0932772132b668f64eddcd;p=thirdparty%2Fccache.git Remove obsolete ScopeGuard --- diff --git a/Makefile.in b/Makefile.in index a5094f035..fbd2aea60 100644 --- a/Makefile.in +++ b/Makefile.in @@ -89,7 +89,6 @@ test_suites += unittest/test_Config.cpp test_suites += unittest/test_FormatNonstdStringView.cpp test_suites += unittest/test_Lockfile.cpp test_suites += unittest/test_NullCompression.cpp -test_suites += unittest/test_ScopeGuard.cpp test_suites += unittest/test_Stat.cpp test_suites += unittest/test_Util.cpp test_suites += unittest/test_ZstdCompression.cpp diff --git a/dev.mk.in b/dev.mk.in index 28121bc77..96f8a1a58 100644 --- a/dev.mk.in +++ b/dev.mk.in @@ -45,7 +45,6 @@ non_third_party_headers_without_cpp = \ src/NullCompressor.hpp \ src/NullDecompressor.hpp \ src/ProgressBar.hpp \ - src/ScopeGuard.hpp \ src/Stat.hpp \ src/StdMakeUnique.hpp \ src/ThreadPool.hpp \ diff --git a/src/ScopeGuard.hpp b/src/ScopeGuard.hpp deleted file mode 100644 index 9827ecd52..000000000 --- a/src/ScopeGuard.hpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2020 Joel Rosdahl and other contributors -// -// See doc/AUTHORS.adoc for a complete list of contributors. -// -// This program is free software; you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the Free -// Software Foundation; either version 3 of the License, or (at your option) -// any later version. -// -// This program is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -// more details. -// -// You should have received a copy of the GNU General Public License along with -// this program; if not, write to the Free Software Foundation, Inc., 51 -// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -#pragma once - -#include "NonCopyable.hpp" - -template struct ScopeGuard : NonCopyable -{ - explicit ScopeGuard(T& guarded) : m_guarded{guarded} - { - } - - ~ScopeGuard() - { - OnExit onexit; - onexit(m_guarded); - } - -private: - T& m_guarded; -}; diff --git a/src/ccache.cpp b/src/ccache.cpp index bd73f6a55..397b45a73 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -25,7 +25,6 @@ #include "File.hpp" #include "FormatNonstdStringView.hpp" #include "ProgressBar.hpp" -#include "ScopeGuard.hpp" #include "Util.hpp" #include "argprocessing.hpp" #include "cleanup.hpp" diff --git a/unittest/test_ScopeGuard.cpp b/unittest/test_ScopeGuard.cpp deleted file mode 100644 index 124305e8e..000000000 --- a/unittest/test_ScopeGuard.cpp +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (C) 2020 Joel Rosdahl and other contributors -// -// See doc/AUTHORS.adoc for a complete list of contributors. -// -// This program is free software; you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the Free -// Software Foundation; either version 3 of the License, or (at your option) -// any later version. -// -// This program is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -// more details. -// -// You should have received a copy of the GNU General Public License along with -// this program; if not, write to the Free Software Foundation, Inc., 51 -// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -#include "NonCopyable.hpp" -#include "ScopeGuard.hpp" - -#include "third_party/catch.hpp" - -struct ptr_deleter -{ - void - operator()(int*& ptr) - { - delete ptr; - ptr = nullptr; - } -}; - -TEST_CASE("delete pointer") -{ - using ScopeGuardInt = ScopeGuard; - int* i = new int(3); - - { - ScopeGuardInt guard(i); - CHECK(*i == 3); - } - - CHECK(i == nullptr); -} - -struct Value : NonCopyable -{ - int i = 3; -}; - -struct reset_value -{ - void - operator()(Value& v) - { - v.i = 0; - } -}; - -TEST_CASE("reset a value type") -{ - using ScopeGuardValue = ScopeGuard; - - Value v; - - CHECK(v.i == 3); - - { - ScopeGuardValue guard(v); - CHECK(v.i == 3); - } - - CHECK(v.i == 0); -}