From 538a426de281e6aa742967a0275d7a51791d96b4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 7 Sep 2021 19:56:43 +0100 Subject: Add -Wold-style-cast and fix up mess, mostly glib stuff --- Jamroot.jam | 1 + libadhocutil/ctf-impl/printf-compat.h | 2 +- libadhocutil/curlHandle.cpp | 21 --------------------- libadhocutil/curlHandle.h | 20 ++++++-------------- libadhocutil/curlStream.cpp | 2 +- libadhocutil/fileUtils.h | 2 +- libadhocutil/lexer-regex.h | 7 +++++-- libadhocutil/lexer.h | 3 +++ libadhocutil/nagios.cpp | 3 ++- libadhocutil/nvpParse.ll | 1 + libadhocutil/processPipes.cpp | 2 +- libadhocutil/resourcePool.impl.h | 2 +- libadhocutil/runtimeContext.cpp | 2 +- libadhocutil/unittests/Jamfile.jam | 1 + libadhocutil/unittests/testCompileTimeFormatter.cpp | 7 ++++--- libadhocutil/unittests/testLazyPointer.cpp | 4 ++-- libadhocutil/unittests/testLexer.cpp | 7 +++++-- 17 files changed, 36 insertions(+), 51 deletions(-) diff --git a/Jamroot.jam b/Jamroot.jam index 5e9bc15..527b990 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -17,6 +17,7 @@ project release:on debug:extra debug:on + debug:-Wold-style-cast coverage:on tidy:bin/sys.h tidy:bin/net.h diff --git a/libadhocutil/ctf-impl/printf-compat.h b/libadhocutil/ctf-impl/printf-compat.h index 33223bf..f05ba30 100644 --- a/libadhocutil/ctf-impl/printf-compat.h +++ b/libadhocutil/ctf-impl/printf-compat.h @@ -73,7 +73,7 @@ namespace AdHoc { static inline void write(stream & s, Obj * const ptr, const Pn &... pn) { - s << std::showbase << std::hex << (long unsigned int)ptr; + s << std::showbase << std::hex << reinterpret_cast(ptr); s.copyfmt(std::ios(nullptr)); StreamWriter::next(s, pn...); } diff --git a/libadhocutil/curlHandle.cpp b/libadhocutil/curlHandle.cpp index b37b725..1df5f12 100644 --- a/libadhocutil/curlHandle.cpp +++ b/libadhocutil/curlHandle.cpp @@ -31,27 +31,6 @@ namespace AdHoc::Net { curl_easy_cleanup(curl_handle); } - template<> - void - CurlHandle::setopt(CURLoption opt, const void * val) - { - curl_easy_setopt(curl_handle, opt, val); - } - - template<> - void - CurlHandle::setopt(CURLoption opt, int val) - { - curl_easy_setopt(curl_handle, opt, val); - } - - template<> - void - CurlHandle::setopt(CURLoption opt, long val) - { - curl_easy_setopt(curl_handle, opt, val); - } - void CurlHandle::getinfo(CURLINFO info, long & val) const { diff --git a/libadhocutil/curlHandle.h b/libadhocutil/curlHandle.h index 6169ec1..1501080 100644 --- a/libadhocutil/curlHandle.h +++ b/libadhocutil/curlHandle.h @@ -24,7 +24,12 @@ namespace AdHoc { virtual ~CurlHandle(); /** Set option wrapper. */ - template void setopt(CURLoption opt, const T val); + template + void + setopt(CURLoption opt, const T & val) + { + curl_easy_setopt(curl_handle, opt, val); + } /** Get info for long values */ void getinfo(CURLINFO info, long & val) const; /** Get info for int values (avoids ambiguous call errors for ease of use) */ @@ -54,19 +59,6 @@ namespace AdHoc { /// @endcond }; using CurlHandlePtr = std::shared_ptr; - - /// @cond - template<> void CurlHandle::setopt(CURLoption opt, const void * val); - template<> void CurlHandle::setopt(CURLoption opt, int val); - template<> void CurlHandle::setopt(CURLoption opt, long val); - template - void - CurlHandle::setopt(CURLoption opt, const T val) - { - setopt(opt, (const void *)val); - } - /// @endcond - } } diff --git a/libadhocutil/curlStream.cpp b/libadhocutil/curlStream.cpp index 3572136..be7f162 100644 --- a/libadhocutil/curlStream.cpp +++ b/libadhocutil/curlStream.cpp @@ -48,7 +48,7 @@ namespace AdHoc::Net { size_t CurlStreamSource::recv(void * data, size_t datalen) { - buf = (char *)data; + buf = static_cast(data); buflen = datalen; swapContext(); return datalen; diff --git a/libadhocutil/fileUtils.h b/libadhocutil/fileUtils.h index fd6ddf2..59bc41e 100644 --- a/libadhocutil/fileUtils.h +++ b/libadhocutil/fileUtils.h @@ -169,7 +169,7 @@ namespace AdHoc { [[nodiscard]] auto sv() const { - return std::basic_string_view((const T *)data, st.st_size / sizeof(T)); + return std::basic_string_view(static_cast(data), st.st_size / sizeof(T)); } #endif diff --git a/libadhocutil/lexer-regex.h b/libadhocutil/lexer-regex.h index 2a087a3..33dbc77 100644 --- a/libadhocutil/lexer-regex.h +++ b/libadhocutil/lexer-regex.h @@ -1,10 +1,13 @@ #ifndef ADHOCUTIL_LEXER_REGEX_H #define ADHOCUTIL_LEXER_REGEX_H -#include "glibmm/ustring.h" #include "lexer.h" // IWYU pragma: export #include "visibility.h" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" #include +#include +#pragma GCC diagnostic pop namespace AdHoc { namespace LexerMatchers { @@ -16,7 +19,7 @@ namespace AdHoc { * @return Pointer to the newly created pattern matcher. */ DLL_PUBLIC Lexer::PatternPtr regex(const Glib::ustring & regex, - GRegexCompileFlags compile = (GRegexCompileFlags)0, GRegexMatchFlags match = (GRegexMatchFlags)0); + GRegexCompileFlags compile = GRegexCompileFlags {}, GRegexMatchFlags match = GRegexMatchFlags {}); } }; diff --git a/libadhocutil/lexer.h b/libadhocutil/lexer.h index 00c1d69..ea1718d 100644 --- a/libadhocutil/lexer.h +++ b/libadhocutil/lexer.h @@ -5,7 +5,10 @@ #include "visibility.h" #include #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" #include +#pragma GCC diagnostic pop #include #include #include diff --git a/libadhocutil/nagios.cpp b/libadhocutil/nagios.cpp index 6c1b095..4350c35 100644 --- a/libadhocutil/nagios.cpp +++ b/libadhocutil/nagios.cpp @@ -27,7 +27,8 @@ namespace AdHoc { struct utsname buf { }; uname(&buf); - NagiosPassiveServiceCheck::write(command_file, time(nullptr), buf.nodename, svc, (uint8_t)code, output); + NagiosPassiveServiceCheck::write( + command_file, time(nullptr), buf.nodename, svc, static_cast(code), output); command_file.flush(); } return command_file.good(); diff --git a/libadhocutil/nvpParse.ll b/libadhocutil/nvpParse.ll index cc3a0e8..9e8b87c 100644 --- a/libadhocutil/nvpParse.ll +++ b/libadhocutil/nvpParse.ll @@ -10,6 +10,7 @@ #include "nvpParse.h" #pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wimplicit-fallthrough" +#pragma GCC diagnostic ignored "-Wold-style-cast" #if __clang__ #pragma GCC diagnostic ignored "-Wnull-conversion" #endif diff --git a/libadhocutil/processPipes.cpp b/libadhocutil/processPipes.cpp index cc0b017..e50d0f1 100644 --- a/libadhocutil/processPipes.cpp +++ b/libadhocutil/processPipes.cpp @@ -134,7 +134,7 @@ namespace AdHoc::System { getrlimit(RLIMIT_NOFILE, &lim); std::vector fds; fds.reserve(lim.rlim_max); - for (int n = 3; n < (int)lim.rlim_max; n += 1) { + for (int n = 3; n < static_cast(lim.rlim_max); n += 1) { fds.push_back({n, 0, 0}); } poll(&fds.front(), fds.size(), 0); diff --git a/libadhocutil/resourcePool.impl.h b/libadhocutil/resourcePool.impl.h index 9fb9d3a..fe77857 100644 --- a/libadhocutil/resourcePool.impl.h +++ b/libadhocutil/resourcePool.impl.h @@ -48,7 +48,7 @@ namespace AdHoc { template ResourceHandle::operator bool() const noexcept { - return (bool)resource; + return resource.operator bool(); } template diff --git a/libadhocutil/runtimeContext.cpp b/libadhocutil/runtimeContext.cpp index 9eeee0d..9ac7cea 100644 --- a/libadhocutil/runtimeContext.cpp +++ b/libadhocutil/runtimeContext.cpp @@ -13,7 +13,7 @@ namespace AdHoc::System { ctxCallback.uc_stack.ss_sp = &stack.front(); ctxCallback.uc_stack.ss_size = stacksize; ctxCallback.uc_link = &ctxInitial; - makecontext(&ctxCallback, (void (*)()) & RuntimeContext::callbackWrapper, 1, this); + makecontext(&ctxCallback, reinterpret_cast(&RuntimeContext::callbackWrapper), 1, this); } void diff --git a/libadhocutil/unittests/Jamfile.jam b/libadhocutil/unittests/Jamfile.jam index 5ca476d..926c4cc 100644 --- a/libadhocutil/unittests/Jamfile.jam +++ b/libadhocutil/unittests/Jamfile.jam @@ -83,6 +83,7 @@ run BOOST_TEST_DYN_LINK ..//adhocutil boost_utf + ..//curl stdc++fs ..//adhocutil : diff --git a/libadhocutil/unittests/testCompileTimeFormatter.cpp b/libadhocutil/unittests/testCompileTimeFormatter.cpp index 885a961..ce782fc 100644 --- a/libadhocutil/unittests/testCompileTimeFormatter.cpp +++ b/libadhocutil/unittests/testCompileTimeFormatter.cpp @@ -383,8 +383,8 @@ GLIBC_FMT_TEST(d051, "in %05d.", 123); GLIBC_FMT_TEST(d0511, "in % 50d.", 123); GLIBC_FMT_TEST(d05121, "in %0510d.", 123); GLIBC_FMT_TEST(d2, "in %d.", 123456); -GLIBC_FMT_TEST(d3, "in %hd.", (int16_t)-12345); -GLIBC_FMT_TEST(d4, "in %hhd.", (int8_t)-123); +GLIBC_FMT_TEST(d3, "in %hd.", static_cast(-12345)); +GLIBC_FMT_TEST(d4, "in %hhd.", static_cast(-123)); GLIBC_FMT_TEST(d5, "in %ld.", -123456L); GLIBC_FMT_TEST(d6, "in %lld.", -123456LL); GLIBC_FMT_TEST(i1, "in %i.", 123); @@ -439,7 +439,8 @@ GLIBC_FMT_TEST(g6, "in %G.", -123.456789); GLIBC_FMT_TEST(g7, "in %g.", 123456789.123); GLIBC_FMT_TEST(g8, "in %g.", -123456789.123); -GLIBC_FMT_TEST(fmtlibt_fmt, "%0.10f:%04d:%+g:%s:%p:%c:%%\n", 1.234, 42, 3.13, "str", (void *)1000, (int)'X'); +GLIBC_FMT_TEST(fmtlibt_fmt, "%0.10f:%04d:%+g:%s:%p:%c:%%\n", 1.234, 42, 3.13, "str", reinterpret_cast(1000), + static_cast('X')); AdHocFormatter(chars_written_fmt, "%n %s %n %d %n"); BOOST_AUTO_TEST_CASE(chars_written) diff --git a/libadhocutil/unittests/testLazyPointer.cpp b/libadhocutil/unittests/testLazyPointer.cpp index 48f0285..f2440bd 100644 --- a/libadhocutil/unittests/testLazyPointer.cpp +++ b/libadhocutil/unittests/testLazyPointer.cpp @@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(rawPointerNonNull) BOOST_REQUIRE(value); BOOST_REQUIRE(value.get()); BOOST_REQUIRE_EQUAL(*value, 3); - int * x = (int *)value; + int * x = value.operator int *(); BOOST_REQUIRE_EQUAL(*x, 3); delete x; } @@ -119,5 +119,5 @@ BOOST_AUTO_TEST_CASE(rawPointerFactory) BOOST_REQUIRE(!value.hasValue()); BOOST_REQUIRE_EQUAL(*value, 4); BOOST_REQUIRE(value.hasValue()); - delete (int *)value; + delete value.operator int *(); } diff --git a/libadhocutil/unittests/testLexer.cpp b/libadhocutil/unittests/testLexer.cpp index 28f98cb..6267dda 100644 --- a/libadhocutil/unittests/testLexer.cpp +++ b/libadhocutil/unittests/testLexer.cpp @@ -1,9 +1,12 @@ #define BOOST_TEST_MODULE Lexer #include -#include "glibmm/ustring.h" #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" #include +#include +#pragma GCC diagnostic pop #include #include #include @@ -79,7 +82,7 @@ BOOST_AUTO_TEST_CASE(multibyte) AdHoc::Lexer::PatternPtr maskHead = AdHoc::LexerMatchers::regex("^# ([^<\n]+)? ?(<(.+?@[^\n>]+)>?)? \\((\\d+ " "*(?:jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\\w* \\d+)\\)$", - (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_CASELESS | G_REGEX_UNGREEDY)); + GRegexCompileFlags(G_REGEX_OPTIMIZE | G_REGEX_CASELESS | G_REGEX_UNGREEDY)); Glib::ustring input("# Michał Górny (28 Mar 2015)"); BOOST_REQUIRE_GT(input.bytes(), input.length()); BOOST_REQUIRE(maskHead->matches(input.c_str(), input.bytes(), 0)); -- cgit v1.2.3