From 53ecceea13d7227c6416ed69be9e06cde6dadaba Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 12 Sep 2021 22:03:04 +0100 Subject: Add -Wuseless-cast, and cppcheck libraryrefs --- Jamroot.jam | 3 +++ libadhocutil/buffer.cpp | 5 ++++- libadhocutil/cache.impl.h | 1 + libadhocutil/lexer.h | 3 +++ libadhocutil/nvpParse.ll | 2 ++ libadhocutil/unittests/testBuffer.cpp | 5 +++-- libadhocutil/unittests/testLazyPointer.cpp | 2 ++ libadhocutil/unittests/testLexer.cpp | 3 +++ libadhocutil/unittests/testProcessPipes.cpp | 1 + libadhocutil/unittests/testSemaphore.cpp | 4 ++++ libadhocutil/unittests/testUriParse.cpp | 2 +- 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 gcc,debug:-Wduplicated-cond gcc,debug:-Wduplicated-branches gcc,debug:-Wlogical-op + gcc,debug:-Wuseless-cast coverage:on tidy:bin/sys.h tidy:bin/net.h @@ -51,6 +52,8 @@ project tidy:performance-* tidy:ICE_IGNORE_VERSION tidy:iwyu.json + tidy:boost + tidy: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(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 + // cppcheck-suppress passedByValue ObjectCacheable::ObjectCacheable(typename Cacheable::Value t, const K & k, time_t vu) : Cacheable(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 #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wold-style-cast" +#ifndef __clang__ +# pragma GCC diagnostic ignored "-Wuseless-cast" +#endif #include #pragma GCC diagnostic pop #include 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; using RawLazyPointer = LazyPointer; /// 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 #include #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()}); } -- cgit v1.2.3