summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-09-12 22:03:04 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-09-12 22:03:04 +0100
commit53ecceea13d7227c6416ed69be9e06cde6dadaba (patch)
treeaf7b5a3464e4be7e91b6baef3f965f0da753f5cc
parentAdd -Wpedantic (diff)
downloadlibadhocutil-53ecceea13d7227c6416ed69be9e06cde6dadaba.tar.bz2
libadhocutil-53ecceea13d7227c6416ed69be9e06cde6dadaba.tar.xz
libadhocutil-53ecceea13d7227c6416ed69be9e06cde6dadaba.zip
Add -Wuseless-cast, and cppcheck libraryrefs
-rw-r--r--Jamroot.jam3
-rw-r--r--libadhocutil/buffer.cpp5
-rw-r--r--libadhocutil/cache.impl.h1
-rw-r--r--libadhocutil/lexer.h3
-rw-r--r--libadhocutil/nvpParse.ll2
-rw-r--r--libadhocutil/unittests/testBuffer.cpp5
-rw-r--r--libadhocutil/unittests/testLazyPointer.cpp2
-rw-r--r--libadhocutil/unittests/testLexer.cpp3
-rw-r--r--libadhocutil/unittests/testProcessPipes.cpp1
-rw-r--r--libadhocutil/unittests/testSemaphore.cpp4
-rw-r--r--libadhocutil/unittests/testUriParse.cpp2
11 files changed, 27 insertions, 4 deletions
diff --git a/Jamroot.jam b/Jamroot.jam
index e3d0edc..c1f55f0 100644
--- a/Jamroot.jam
+++ b/Jamroot.jam
@@ -31,6 +31,7 @@ project
<toolset>gcc,<variant>debug:<cflags>-Wduplicated-cond
<toolset>gcc,<variant>debug:<cflags>-Wduplicated-branches
<toolset>gcc,<variant>debug:<cflags>-Wlogical-op
+ <toolset>gcc,<variant>debug:<cflags>-Wuseless-cast
<variant>coverage:<coverage>on
<toolset>tidy:<exclude>bin/sys.h
<toolset>tidy:<exclude>bin/net.h
@@ -51,6 +52,8 @@ project
<toolset>tidy:<checkxx>performance-*
<toolset>tidy:<define>ICE_IGNORE_VERSION
<toolset>tidy:<mapping>iwyu.json
+ <toolset>tidy:<librarydef>boost
+ <toolset>tidy:<librarydef>std
;
build-project libadhocutil ;
diff --git a/libadhocutil/buffer.cpp b/libadhocutil/buffer.cpp
index 26e15fc..dec3586 100644
--- a/libadhocutil/buffer.cpp
+++ b/libadhocutil/buffer.cpp
@@ -155,7 +155,10 @@ namespace AdHoc {
Buffer::vappendf(const char * fmt, va_list args)
{
char * frag;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
const auto len = vasprintf(&frag, fmt, args);
+#pragma GCC diagnostic pop
if (len > 0) {
content.push_back(std::make_shared<CStringFragment>(frag, Free, len));
}
@@ -214,7 +217,7 @@ namespace AdHoc {
return res;
}
else if (content.size() == 1) {
- return std::string(content.front()->str());
+ return content.front()->str();
}
return std::string();
}
diff --git a/libadhocutil/cache.impl.h b/libadhocutil/cache.impl.h
index e26bf30..7ba5853 100644
--- a/libadhocutil/cache.impl.h
+++ b/libadhocutil/cache.impl.h
@@ -19,6 +19,7 @@ namespace AdHoc {
}
template<typename T, typename K>
+ // cppcheck-suppress passedByValue
ObjectCacheable<T, K>::ObjectCacheable(typename Cacheable<T, K>::Value t, const K & k, time_t vu) :
Cacheable<T, K>(k, vu), value(std::move(t))
{
diff --git a/libadhocutil/lexer.h b/libadhocutil/lexer.h
index ea1718d..d6ec249 100644
--- a/libadhocutil/lexer.h
+++ b/libadhocutil/lexer.h
@@ -7,6 +7,9 @@
#include <functional>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
+#ifndef __clang__
+# pragma GCC diagnostic ignored "-Wuseless-cast"
+#endif
#include <glib.h>
#pragma GCC diagnostic pop
#include <memory>
diff --git a/libadhocutil/nvpParse.ll b/libadhocutil/nvpParse.ll
index af082ce..519ccad 100644
--- a/libadhocutil/nvpParse.ll
+++ b/libadhocutil/nvpParse.ll
@@ -14,6 +14,8 @@
#pragma GCC diagnostic ignored "-Wold-style-cast"
#if __clang__
#pragma GCC diagnostic ignored "-Wnull-conversion"
+#else
+#pragma GCC diagnostic ignored "-Wuseless-cast"
#endif
%}
diff --git a/libadhocutil/unittests/testBuffer.cpp b/libadhocutil/unittests/testBuffer.cpp
index 1457cb3..5184427 100644
--- a/libadhocutil/unittests/testBuffer.cpp
+++ b/libadhocutil/unittests/testBuffer.cpp
@@ -66,8 +66,9 @@ BOOST_AUTO_TEST_CASE(appendthings)
BOOST_REQUIRE_EQUAL(22, b.length());
BOOST_REQUIRE_EQUAL("string a b num 1 num 2", b.str());
const char * cstring = b;
- BOOST_REQUIRE_EQUAL(22, strlen(cstring));
- BOOST_REQUIRE_EQUAL("string a b num 1 num 2", cstring);
+ std::string_view sv {cstring};
+ BOOST_REQUIRE_EQUAL(22, sv.length());
+ BOOST_REQUIRE_EQUAL("string a b num 1 num 2", sv);
}
BOOST_AUTO_TEST_CASE(writeto)
diff --git a/libadhocutil/unittests/testLazyPointer.cpp b/libadhocutil/unittests/testLazyPointer.cpp
index 0c8067b..481427a 100644
--- a/libadhocutil/unittests/testLazyPointer.cpp
+++ b/libadhocutil/unittests/testLazyPointer.cpp
@@ -17,7 +17,9 @@ using TestLazyPointer = LazyPointer<Test>;
using RawLazyPointer = LazyPointer<int, int *>;
/// LCOV_EXCL_START (diagnostics)
+// cppcheck-suppress unknownMacro
BOOST_TEST_DONT_PRINT_LOG_VALUE(TestLazyPointer)
+// cppcheck-suppress unknownMacro
BOOST_TEST_DONT_PRINT_LOG_VALUE(RawLazyPointer)
/// LCOV_EXCL_STOP
diff --git a/libadhocutil/unittests/testLexer.cpp b/libadhocutil/unittests/testLexer.cpp
index 837eaf3..b8411c2 100644
--- a/libadhocutil/unittests/testLexer.cpp
+++ b/libadhocutil/unittests/testLexer.cpp
@@ -5,6 +5,9 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#pragma GCC diagnostic ignored "-Wsign-conversion"
+#ifndef __clang__
+# pragma GCC diagnostic ignored "-Wuseless-cast"
+#endif
#include <glib.h>
#include <glibmm/ustring.h>
#pragma GCC diagnostic pop
diff --git a/libadhocutil/unittests/testProcessPipes.cpp b/libadhocutil/unittests/testProcessPipes.cpp
index 90b0354..ac6330a 100644
--- a/libadhocutil/unittests/testProcessPipes.cpp
+++ b/libadhocutil/unittests/testProcessPipes.cpp
@@ -38,6 +38,7 @@ BOOST_AUTO_TEST_CASE(readwrite)
BOOST_REQUIRE_NE(pp.fdOut(), -1);
BOOST_REQUIRE_EQUAL(pp.fdError(), -1);
BOOST_REQUIRE_EQUAL(11, write(pp.fdIn(), "some string", 11));
+ // cppcheck-suppress assertWithSideEffect
BOOST_REQUIRE_EQUAL(0, pp.closeIn());
std::string out(32, ' ');
BOOST_REQUIRE_EQUAL(32, read(pp.fdOut(), out.data(), 32));
diff --git a/libadhocutil/unittests/testSemaphore.cpp b/libadhocutil/unittests/testSemaphore.cpp
index fcc6578..0de899e 100644
--- a/libadhocutil/unittests/testSemaphore.cpp
+++ b/libadhocutil/unittests/testSemaphore.cpp
@@ -17,6 +17,7 @@ BOOST_AUTO_TEST_CASE(initial)
AdHoc::Semaphore s(2);
s.wait();
s.wait();
+ // cppcheck-suppress assertWithSideEffect
BOOST_REQUIRE_EQUAL(false, s.wait(0));
}
@@ -43,7 +44,9 @@ BOOST_AUTO_TEST_CASE(addRemoveTimeOut)
AdHoc::Semaphore s;
s.notify();
s.wait();
+ // cppcheck-suppress assertWithSideEffect
BOOST_REQUIRE_EQUAL(false, s.wait(100));
+ // cppcheck-suppress assertWithSideEffect
BOOST_REQUIRE_EQUAL(false, s.wait(0));
}
@@ -56,6 +59,7 @@ BOOST_AUTO_TEST_CASE(addRemoveWait)
usleep(100000);
s.notify();
});
+ // cppcheck-suppress assertWithSideEffect
BOOST_REQUIRE_EQUAL(false, s.wait(1));
s.wait();
th.join();
diff --git a/libadhocutil/unittests/testUriParse.cpp b/libadhocutil/unittests/testUriParse.cpp
index ecb8049..51e8571 100644
--- a/libadhocutil/unittests/testUriParse.cpp
+++ b/libadhocutil/unittests/testUriParse.cpp
@@ -273,5 +273,5 @@ BOOST_AUTO_TEST_CASE(bad)
BOOST_CHECK_THROW(AdHoc::Uri("tcp://user:pass@"), AdHoc::InvalidUri);
AdHoc::InvalidUri ui("message", "http://localhost");
- BOOST_CHECK_EQUAL("InvalidUri (message) parsing [http://localhost]", ui.what());
+ BOOST_CHECK_EQUAL("InvalidUri (message) parsing [http://localhost]", std::string_view {ui.what()});
}