From 4a91319ece89e00211dddc62eed8d143c3804e86 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 12 Sep 2021 19:10:32 +0100 Subject: Add -Wpedantic --- Jamroot.jam | 1 + libadhocutil/compileTimeFormatter.h | 15 +- libadhocutil/ctf-impl/printf-compat.h | 10 +- libadhocutil/globalStatic.impl.h | 2 +- libadhocutil/lexer-regex.h | 2 +- libadhocutil/unittests/testCaseLess.cpp | 2 +- .../unittests/testCompileTimeFormatter.cpp | 160 ++++++++++----------- libadhocutil/unittests/testFactory.cpp | 10 +- libadhocutil/unittests/testLazyPointer.cpp | 4 +- libadhocutil/unittests/testMemStream.cpp | 4 +- libadhocutil/unittests/testNvpParse.cpp | 2 +- libadhocutil/unittests/utilTestClasses.cpp | 4 +- 12 files changed, 110 insertions(+), 106 deletions(-) diff --git a/Jamroot.jam b/Jamroot.jam index c528089..e3d0edc 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -22,6 +22,7 @@ project debug:-Wcast-align debug:-Wunused debug:-Woverloaded-virtual + debug:-Wpedantic debug:-Wconversion debug:-Wsign-conversion debug:-Wnull-dereference diff --git a/libadhocutil/compileTimeFormatter.h b/libadhocutil/compileTimeFormatter.h index de7376b..2524043 100644 --- a/libadhocutil/compileTimeFormatter.h +++ b/libadhocutil/compileTimeFormatter.h @@ -106,15 +106,15 @@ namespace AdHoc { } }; -#define StreamWriterT(C...) \ +#define StreamWriterT(...) \ template \ - struct StreamWriter : \ - public StreamWriterBase + struct StreamWriter : \ + public StreamWriterBase -#define StreamWriterTP(P, C...) \ +#define StreamWriterTP(P, ...) \ template \ - struct StreamWriter : \ - public StreamWriterBase + struct StreamWriter : \ + public StreamWriterBase // Default stream writer formatter StreamWriterT('?') { @@ -317,6 +317,8 @@ namespace AdHoc { return AdHoc::FormatterDetail(); } #else +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wpedantic" # ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wgnu-string-literal-operator-template" @@ -335,6 +337,7 @@ namespace AdHoc { #ifdef __clang__ # pragma clang diagnostic pop #endif +#pragma GCC diagnostic pop } } diff --git a/libadhocutil/ctf-impl/printf-compat.h b/libadhocutil/ctf-impl/printf-compat.h index 872f9af..aa0ead9 100644 --- a/libadhocutil/ctf-impl/printf-compat.h +++ b/libadhocutil/ctf-impl/printf-compat.h @@ -29,7 +29,7 @@ namespace AdHoc { BASICCONV(BASE, OP, CONV); \ BASICCONV(short BASE, OP, 'h', CONV); \ BASICCONV(long BASE, OP, 'l', CONV); \ - BASICCONV(long long BASE, OP, 'l', 'l', CONV); + BASICCONV(long long BASE, OP, 'l', 'l', CONV) INTCONV(int, s << std::dec << p, 'i'); INTCONV(int, s << std::dec << p, 'd'); INTCONV(unsigned int, s << std::oct << p, 'o'); @@ -52,7 +52,7 @@ namespace AdHoc { // Floating point (a, A, e, E, f, F, g, G) #define FPCONV(BASE, OP, CONV) \ BASICCONV(BASE, OP, CONV); \ - BASICCONV(long BASE, OP, 'L', CONV); + BASICCONV(long BASE, OP, 'L', CONV) FPCONV(double, s << std::nouppercase << std::hexfloat << p, 'a'); FPCONV(double, s << std::uppercase << std::hexfloat << p, 'A'); FPCONV(double, s << std::nouppercase << std::scientific << p, 'e'); @@ -144,7 +144,7 @@ namespace AdHoc { StreamWriter::write(s, pn...); \ } \ }; - BOOST_PP_REPEAT(6, FMTWIDTH, void); + BOOST_PP_REPEAT(6, FMTWIDTH, void) #define FMTPRECISION(unused, d, data) \ template \ @@ -160,7 +160,7 @@ namespace AdHoc { StreamWriter::write(s, pn...); \ } \ }; - BOOST_PP_REPEAT(6, FMTPRECISION, void); + BOOST_PP_REPEAT(6, FMTPRECISION, void) #undef AUTON #undef NS #undef ISDIGIT @@ -202,7 +202,7 @@ namespace AdHoc { OP; \ StreamWriter::write(s, pn...); \ } \ - }; + } FLAGCONV(s << std::showbase, '#'); FLAGCONV(s << std::setfill('0'), '0'); FLAGCONV(s << std::left, '-'); diff --git a/libadhocutil/globalStatic.impl.h b/libadhocutil/globalStatic.impl.h index fd611c3..ba12da8 100644 --- a/libadhocutil/globalStatic.impl.h +++ b/libadhocutil/globalStatic.impl.h @@ -33,6 +33,6 @@ namespace AdHoc { static Ptr _instance; return _instance; } -}; +} #endif diff --git a/libadhocutil/lexer-regex.h b/libadhocutil/lexer-regex.h index a469987..0673458 100644 --- a/libadhocutil/lexer-regex.h +++ b/libadhocutil/lexer-regex.h @@ -22,6 +22,6 @@ namespace AdHoc { DLL_PUBLIC Lexer::PatternPtr regex(const Glib::ustring & regex, GRegexCompileFlags compile = GRegexCompileFlags {}, GRegexMatchFlags match = GRegexMatchFlags {}); } -}; +} #endif diff --git a/libadhocutil/unittests/testCaseLess.cpp b/libadhocutil/unittests/testCaseLess.cpp index 90d06de..e92f8af 100644 --- a/libadhocutil/unittests/testCaseLess.cpp +++ b/libadhocutil/unittests/testCaseLess.cpp @@ -5,7 +5,7 @@ #include #include -BOOST_FIXTURE_TEST_SUITE(l, AdHoc::case_less); +BOOST_FIXTURE_TEST_SUITE(l, AdHoc::case_less) BOOST_AUTO_TEST_CASE(case_less_test) { diff --git a/libadhocutil/unittests/testCompileTimeFormatter.cpp b/libadhocutil/unittests/testCompileTimeFormatter.cpp index a6968c4..877f3e8 100644 --- a/libadhocutil/unittests/testCompileTimeFormatter.cpp +++ b/libadhocutil/unittests/testCompileTimeFormatter.cpp @@ -132,7 +132,7 @@ static_assert(strchrnul() == 3); static_assert(strchrnul() == 7); #endif -BOOST_FIXTURE_TEST_SUITE(TestStreamWrite, std::stringstream); +BOOST_FIXTURE_TEST_SUITE(TestStreamWrite, std::stringstream) BOOST_AUTO_TEST_CASE(empty) { @@ -268,7 +268,7 @@ BOOST_AUTO_TEST_CASE(longFormatString) BOOST_CHECK_EQUAL(this->str().length(), 246); } -BOOST_AUTO_TEST_SUITE_END(); +BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_CASE(customMultiArgRightAlign) { @@ -361,86 +361,86 @@ static_assert(419 == decdigits<'0', '4', '1', '9'>()); } \ } -GLIBC_FMT_TEST(s1, "in %s.", "string"); -GLIBC_FMT_TEST(s2, "in %s %s.", "string", "other"); -GLIBC_FMT_TEST(s3, "in %.*s.", 3, "other"); -GLIBC_FMT_TEST(s4, "in %.*s.", 5, "other"); -GLIBC_FMT_TEST(s5, "in %.*s.", 7, "other"); -GLIBC_FMT_TEST(s35, "in %3s.", "other"); -GLIBC_FMT_TEST(s55, "in %5s.", "other"); -GLIBC_FMT_TEST(s115, "in %11s.", "other"); +GLIBC_FMT_TEST(s1, "in %s.", "string") +GLIBC_FMT_TEST(s2, "in %s %s.", "string", "other") +GLIBC_FMT_TEST(s3, "in %.*s.", 3, "other") +GLIBC_FMT_TEST(s4, "in %.*s.", 5, "other") +GLIBC_FMT_TEST(s5, "in %.*s.", 7, "other") +GLIBC_FMT_TEST(s35, "in %3s.", "other") +GLIBC_FMT_TEST(s55, "in %5s.", "other") +GLIBC_FMT_TEST(s115, "in %11s.", "other") // std::setw does not truncate strings -// GLIBC_FMT_TEST(sd35, "in %.3s.", "other"); -GLIBC_FMT_TEST(sd55, "in %.5s.", "other"); -GLIBC_FMT_TEST(sd115, "in %.11s.", "other"); - -GLIBC_FMT_TEST(c1, "in %c.", 'b'); -GLIBC_FMT_TEST(c2, "in %c.", 'B'); - -GLIBC_FMT_TEST(d1, "in %d.", 123); -GLIBC_FMT_TEST(d01, "in %0d.", 123); -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.", 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); -GLIBC_FMT_TEST(i2, "in %i.", -123); - -GLIBC_FMT_TEST(x1, "in %x.", 123U); -GLIBC_FMT_TEST(x2, "in %x %d.", 123U, 256); -GLIBC_FMT_TEST(x3, "in %d %x.", 123, 1024U); -GLIBC_FMT_TEST(x4, "in %X %x.", 123U, 13U); -GLIBC_FMT_TEST(x5, "in %X %s.", 123U, "miXED case after UPPER X"); -GLIBC_FMT_TEST(x6, "in %#x.", 123U); -GLIBC_FMT_TEST(x7, "in %#X.", 123U); -GLIBC_FMT_TEST(x8, "in %#X %x.", 123U, 150U); - -GLIBC_FMT_TEST(o1, "in %o.", 123U); -GLIBC_FMT_TEST(o2, "in %o %d.", 123U, 256); -GLIBC_FMT_TEST(o3, "in %d %o.", 123, 1024U); - -GLIBC_FMT_TEST(a1, "in %a.", 123.456789); -GLIBC_FMT_TEST(a2, "in %a.", -123.456789); -GLIBC_FMT_TEST(a3, "in %a.", .123456789); -GLIBC_FMT_TEST(a4, "in %a.", -.123456789); -GLIBC_FMT_TEST(a5, "in %A.", -.123456789); -GLIBC_FMT_TEST(a6, "in %A.", -123.456789); -GLIBC_FMT_TEST(a7, "in %a.", 123456789.123); -GLIBC_FMT_TEST(a8, "in %a.", -123456789.123); - -GLIBC_FMT_TEST(e1, "in %e.", 123.456789); -GLIBC_FMT_TEST(e2, "in %e.", -123.456789); -GLIBC_FMT_TEST(e3, "in %e.", .123456789); -GLIBC_FMT_TEST(e4, "in %e.", -.123456789); -GLIBC_FMT_TEST(e5, "in %E.", -.123456789); -GLIBC_FMT_TEST(e6, "in %E.", -123.456789); -GLIBC_FMT_TEST(e7, "in %e.", 123456789.123); -GLIBC_FMT_TEST(e8, "in %e.", -123456789.123); - -GLIBC_FMT_TEST(f1, "in %f.", 123.456789); -GLIBC_FMT_TEST(f2, "in %f.", -123.456789); -GLIBC_FMT_TEST(f3, "in %f.", .123456789); -GLIBC_FMT_TEST(f4, "in %f.", -.123456789); -GLIBC_FMT_TEST(f5, "in %F.", -.123456789); -GLIBC_FMT_TEST(f6, "in %F.", -123.456789); -GLIBC_FMT_TEST(f7, "in %f.", 123456789.123); -GLIBC_FMT_TEST(f8, "in %f.", -123456789.123); - -GLIBC_FMT_TEST(g1, "in %g.", 123.456789); -GLIBC_FMT_TEST(g2, "in %g.", -123.456789); -GLIBC_FMT_TEST(g3, "in %g.", .123456789); -GLIBC_FMT_TEST(g4, "in %g.", -.123456789); -GLIBC_FMT_TEST(g5, "in %G.", -.123456789); -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(sd35, "in %.3s.", "other") +GLIBC_FMT_TEST(sd55, "in %.5s.", "other") +GLIBC_FMT_TEST(sd115, "in %.11s.", "other") + +GLIBC_FMT_TEST(c1, "in %c.", 'b') +GLIBC_FMT_TEST(c2, "in %c.", 'B') + +GLIBC_FMT_TEST(d1, "in %d.", 123) +GLIBC_FMT_TEST(d01, "in %0d.", 123) +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.", 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) +GLIBC_FMT_TEST(i2, "in %i.", -123) + +GLIBC_FMT_TEST(x1, "in %x.", 123U) +GLIBC_FMT_TEST(x2, "in %x %d.", 123U, 256) +GLIBC_FMT_TEST(x3, "in %d %x.", 123, 1024U) +GLIBC_FMT_TEST(x4, "in %X %x.", 123U, 13U) +GLIBC_FMT_TEST(x5, "in %X %s.", 123U, "miXED case after UPPER X") +GLIBC_FMT_TEST(x6, "in %#x.", 123U) +GLIBC_FMT_TEST(x7, "in %#X.", 123U) +GLIBC_FMT_TEST(x8, "in %#X %x.", 123U, 150U) + +GLIBC_FMT_TEST(o1, "in %o.", 123U) +GLIBC_FMT_TEST(o2, "in %o %d.", 123U, 256) +GLIBC_FMT_TEST(o3, "in %d %o.", 123, 1024U) + +GLIBC_FMT_TEST(a1, "in %a.", 123.456789) +GLIBC_FMT_TEST(a2, "in %a.", -123.456789) +GLIBC_FMT_TEST(a3, "in %a.", .123456789) +GLIBC_FMT_TEST(a4, "in %a.", -.123456789) +GLIBC_FMT_TEST(a5, "in %A.", -.123456789) +GLIBC_FMT_TEST(a6, "in %A.", -123.456789) +GLIBC_FMT_TEST(a7, "in %a.", 123456789.123) +GLIBC_FMT_TEST(a8, "in %a.", -123456789.123) + +GLIBC_FMT_TEST(e1, "in %e.", 123.456789) +GLIBC_FMT_TEST(e2, "in %e.", -123.456789) +GLIBC_FMT_TEST(e3, "in %e.", .123456789) +GLIBC_FMT_TEST(e4, "in %e.", -.123456789) +GLIBC_FMT_TEST(e5, "in %E.", -.123456789) +GLIBC_FMT_TEST(e6, "in %E.", -123.456789) +GLIBC_FMT_TEST(e7, "in %e.", 123456789.123) +GLIBC_FMT_TEST(e8, "in %e.", -123456789.123) + +GLIBC_FMT_TEST(f1, "in %f.", 123.456789) +GLIBC_FMT_TEST(f2, "in %f.", -123.456789) +GLIBC_FMT_TEST(f3, "in %f.", .123456789) +GLIBC_FMT_TEST(f4, "in %f.", -.123456789) +GLIBC_FMT_TEST(f5, "in %F.", -.123456789) +GLIBC_FMT_TEST(f6, "in %F.", -123.456789) +GLIBC_FMT_TEST(f7, "in %f.", 123456789.123) +GLIBC_FMT_TEST(f8, "in %f.", -123456789.123) + +GLIBC_FMT_TEST(g1, "in %g.", 123.456789) +GLIBC_FMT_TEST(g2, "in %g.", -123.456789) +GLIBC_FMT_TEST(g3, "in %g.", .123456789) +GLIBC_FMT_TEST(g4, "in %g.", -.123456789) +GLIBC_FMT_TEST(g5, "in %G.", -.123456789) +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", reinterpret_cast(1000), 'X'); + fmtlibt_fmt, "%0.10f:%04d:%+g:%s:%p:%c:%%\n", 1.234, 42, 3.13, "str", reinterpret_cast(1000), 'X') AdHocFormatter(chars_written_fmt, "%n %s %n %d %n"); BOOST_AUTO_TEST_CASE(chars_written) @@ -453,7 +453,7 @@ BOOST_AUTO_TEST_CASE(chars_written) BOOST_CHECK_EQUAL(c, s.length()); } -GLIBC_FMT_TEST(p2, "in %p.", this); +GLIBC_FMT_TEST(p2, "in %p.", static_cast(this)) AdHocFormatter(smartptr_fmt, "Address is %p."); BOOST_AUTO_TEST_CASE(smartptr) diff --git a/libadhocutil/unittests/testFactory.cpp b/libadhocutil/unittests/testFactory.cpp index 17b220e..dbd4eb8 100644 --- a/libadhocutil/unittests/testFactory.cpp +++ b/libadhocutil/unittests/testFactory.cpp @@ -44,14 +44,14 @@ public: using BaseThingFactory = AdHoc::Factory; -NAMEDFACTORY("a", ImplOfThing, BaseThingFactory); -FACTORY(OtherImplOfThing, BaseThingFactory); +NAMEDFACTORY("a", ImplOfThing, BaseThingFactory) +FACTORY(OtherImplOfThing, BaseThingFactory) -INSTANTIATEFACTORY(BaseThing, int, std::string *); +INSTANTIATEFACTORY(BaseThing, int, std::string *) // Multiple factories in one compilation unit -INSTANTIATEFACTORY(BaseThing, std::string, std::string); +INSTANTIATEFACTORY(BaseThing, std::string, std::string) // Factories of things with commas -INSTANTIATEFACTORY(BaseThing, std::map); +INSTANTIATEFACTORY(BaseThing, std::map) BOOST_AUTO_TEST_CASE(ready) { diff --git a/libadhocutil/unittests/testLazyPointer.cpp b/libadhocutil/unittests/testLazyPointer.cpp index c3bbbfe..0c8067b 100644 --- a/libadhocutil/unittests/testLazyPointer.cpp +++ b/libadhocutil/unittests/testLazyPointer.cpp @@ -17,8 +17,8 @@ using TestLazyPointer = LazyPointer; using RawLazyPointer = LazyPointer; /// LCOV_EXCL_START (diagnostics) -BOOST_TEST_DONT_PRINT_LOG_VALUE(TestLazyPointer); -BOOST_TEST_DONT_PRINT_LOG_VALUE(RawLazyPointer); +BOOST_TEST_DONT_PRINT_LOG_VALUE(TestLazyPointer) +BOOST_TEST_DONT_PRINT_LOG_VALUE(RawLazyPointer) /// LCOV_EXCL_STOP static TestLazyPointer::pointer_type diff --git a/libadhocutil/unittests/testMemStream.cpp b/libadhocutil/unittests/testMemStream.cpp index 0432067..3f8a160 100644 --- a/libadhocutil/unittests/testMemStream.cpp +++ b/libadhocutil/unittests/testMemStream.cpp @@ -9,7 +9,7 @@ using namespace AdHoc; -BOOST_FIXTURE_TEST_SUITE(s, MemStream); +BOOST_FIXTURE_TEST_SUITE(s, MemStream) BOOST_AUTO_TEST_CASE(empty) { @@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE(simple) BOOST_CHECK_EQUAL(len, this->length()); } -BOOST_AUTO_TEST_SUITE_END(); +BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_CASE(move_construct) { diff --git a/libadhocutil/unittests/testNvpParse.cpp b/libadhocutil/unittests/testNvpParse.cpp index ef148f5..7fd500d 100644 --- a/libadhocutil/unittests/testNvpParse.cpp +++ b/libadhocutil/unittests/testNvpParse.cpp @@ -26,7 +26,7 @@ NvpTarget(TestTarget) TestTargetMap { }; /// LCOV_EXCL_START (diagnostics) -BOOST_TEST_DONT_PRINT_LOG_VALUE(decltype(TestTargetMap.find(""))); +BOOST_TEST_DONT_PRINT_LOG_VALUE(decltype(TestTargetMap.find(""))) /// LCOV_EXCL_STOP BOOST_AUTO_TEST_CASE(targetmap) diff --git a/libadhocutil/unittests/utilTestClasses.cpp b/libadhocutil/unittests/utilTestClasses.cpp index d42b9aa..b193bd1 100644 --- a/libadhocutil/unittests/utilTestClasses.cpp +++ b/libadhocutil/unittests/utilTestClasses.cpp @@ -1,5 +1,5 @@ #include "utilTestClasses.h" #include "plugins.impl.h" -PLUGIN(ImplOfThing, BaseThing); -INSTANTIATEPLUGINOF(BaseThing); +PLUGIN(ImplOfThing, BaseThing) +INSTANTIATEPLUGINOF(BaseThing) -- cgit v1.2.3