From 30fc8736266debf845ed2c5b8d112e1626b8a333 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 25 Aug 2020 16:54:23 +0200 Subject: [PATCH 01/27] Remove useless hdrstop pragma from allheaders test It shouldn't be necessary for a test not using PCH at all and Borland compiler is almost certainly not supported anyhow any longer. --- tests/allheaders.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/allheaders.cpp b/tests/allheaders.cpp index bcf0581a8f..5f3e4a94c6 100644 --- a/tests/allheaders.cpp +++ b/tests/allheaders.cpp @@ -10,11 +10,6 @@ // headers // ---------------------------------------------------------------------------- -// Avoid pre-compiled headers at all -#ifdef __BORLANDC__ - #pragma hdrstop -#endif - #include "wx/setup.h" #if !wxUSE_UTF8_LOCALE_ONLY From 054d98b1df927e3a3a59bd5c00f4d571e678ced1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 25 Aug 2020 17:36:02 +0200 Subject: [PATCH 02/27] Fix -Wpedantic in wxDECLARE_ABSTRACT_CLASS() Fix a regression introduced in c924ecb10a (Suppress -Wsuggest-override warnings in user code for gcc too, 2020-07-27) and rearrange the macro to make sure a semicolon is necessary after it. Closes #18901. --- include/wx/rtti.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/wx/rtti.h b/include/wx/rtti.h index 15e270d539..09faa06d51 100644 --- a/include/wx/rtti.h +++ b/include/wx/rtti.h @@ -139,10 +139,10 @@ WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxString& name); #define wxDECLARE_ABSTRACT_CLASS(name) \ public: \ - static wxClassInfo ms_classInfo; \ wxWARNING_SUPPRESS_MISSING_OVERRIDE() \ virtual wxClassInfo *GetClassInfo() const; \ - wxWARNING_RESTORE_MISSING_OVERRIDE() + wxWARNING_RESTORE_MISSING_OVERRIDE() \ + static wxClassInfo ms_classInfo #define wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \ wxDECLARE_NO_ASSIGN_CLASS(name); \ From 1ec571fb64101aa3a0dd6d1fa7eef06243815639 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 25 Aug 2020 17:37:25 +0200 Subject: [PATCH 03/27] Avoid -Wshadow warnings when using multiple wxCHECK()s If the same function used any of macros from wxCHECK() family more than once, wxDummyCheckStruct was redeclared, resulting in -Wshadow warnings from gcc. Fix this by using unique names for the dummy macro. --- include/wx/debug.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/wx/debug.h b/include/wx/debug.h index 406b4740a0..c9e78c6f9f 100644 --- a/include/wx/debug.h +++ b/include/wx/debug.h @@ -371,7 +371,7 @@ extern void WXDLLIMPEXP_BASE wxAbort(); wxFAIL_COND_MSG(#cond, msg); \ op; \ } \ - struct wxDummyCheckStruct /* just to force a semicolon */ + struct wxMAKE_UNIQUE_NAME(wxDummyCheckStruct) /* to force a semicolon */ // check which returns with the specified return code if the condition fails #define wxCHECK_MSG(cond, rc, msg) wxCHECK2_MSG(cond, return rc, msg) From 23334af81bc437dbf0c7ad22b23dd807b4d1d2d5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 25 Aug 2020 17:39:09 +0200 Subject: [PATCH 04/27] Test headers compilation with maximum warnings options with gcc As wx headers are included from user applications which may compile with higher warning level than wx itself, try to check headers compilation with almost all of gcc warning flags turned on. This notably should prevent the headers from becoming uncompilable with -pedantic again in the future. --- tests/allheaders.cpp | 389 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 389 insertions(+) diff --git a/tests/allheaders.cpp b/tests/allheaders.cpp index 5f3e4a94c6..510f858495 100644 --- a/tests/allheaders.cpp +++ b/tests/allheaders.cpp @@ -10,8 +10,392 @@ // headers // ---------------------------------------------------------------------------- +// Note: can't use wxCHECK_GCC_VERSION() here as it's not defined yet. +#if defined(__GNUC__) + #define CHECK_GCC_VERSION(major, minor) \ + (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) +#else + #define CHECK_GCC_VERSION(major, minor) 0 +#endif + +#if CHECK_GCC_VERSION(4, 6) + // As above, we can't reuse wxCONCAT() and wxSTRINGIZE macros from wx/cpp.h + // here, so define their equivalents here. + #define CONCAT_HELPER(x, y) x ## y + #define CONCAT(x1, x2) CONCAT_HELPER(x1, x2) + + #define STRINGIZE_HELPER(x) #x + #define STRINGIZE(x) STRINGIZE_HELPER(x) + + #define GCC_TURN_ON(warn) \ + _Pragma(STRINGIZE(GCC diagnostic error STRINGIZE(CONCAT(-W,warn)))) + #define GCC_TURN_OFF(warn) \ + _Pragma(STRINGIZE(GCC diagnostic ignored STRINGIZE(CONCAT(-W,warn)))) +#endif + +// Due to what looks like a bug in gcc, some warnings enabled after including +// the standard headers still result in warnings being given when instantiating +// some functions defined in these headers later and we need to explicitly +// disable these warnings to avoid them, even if they're not enabled yet. +#ifdef GCC_TURN_OFF + #pragma GCC diagnostic push + + GCC_TURN_OFF(aggregate-return) + GCC_TURN_OFF(conversion) + GCC_TURN_OFF(padded) + GCC_TURN_OFF(parentheses) + GCC_TURN_OFF(sign-compare) + GCC_TURN_OFF(sign-conversion) + GCC_TURN_OFF(unused-parameter) + GCC_TURN_OFF(zero-as-null-pointer-constant) +#endif + +// We have to include this one first in order to check for HAVE_XXX below. #include "wx/setup.h" +// Include all standard headers that are used in wx headers before enabling the +// warnings below. +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(HAVE_STD_UNORDERED_MAP) + #include +#endif +#if defined(HAVE_STD_UNORDERED_SET) + #include +#endif + +#if defined(HAVE_DLOPEN) + #include +#endif +#include + +#include "catch.hpp" + +#ifdef GCC_TURN_OFF + #pragma GCC diagnostic pop +#endif + +// Enable max warning level for headers if possible, using gcc pragmas. +#ifdef GCC_TURN_ON + // Enable all the usual "maximal" warnings. + GCC_TURN_ON(all) + GCC_TURN_ON(extra) + GCC_TURN_ON(pedantic) + + // Enable all the individual warnings not enabled by one of the warnings + // above. + + // Start of semi-auto-generated part, don't modify it manually. + // + // Manual changes: + // - Globally replace HANDLE_GCC_WARNING with GCC_TURN_ON. + // - Add v6 check for -Wabi, gcc < 6 don't seem to support turning it off + // once it's turned on and gives it for the standard library symbols. + // {{{ +#if CHECK_GCC_VERSION(6,1) + GCC_TURN_ON(abi) +#endif // 6.1 +#if CHECK_GCC_VERSION(4,8) + GCC_TURN_ON(abi-tag) +#endif // 4.8 + GCC_TURN_ON(address) + GCC_TURN_ON(aggregate-return) +#if CHECK_GCC_VERSION(7,1) + GCC_TURN_ON(alloc-zero) +#endif // 7.1 +#if CHECK_GCC_VERSION(7,1) + GCC_TURN_ON(alloca) +#endif // 7.1 +#if CHECK_GCC_VERSION(10,1) + GCC_TURN_ON(arith-conversion) +#endif // 10.1 + GCC_TURN_ON(array-bounds) + GCC_TURN_ON(builtin-macro-redefined) + GCC_TURN_ON(cast-align) +#if CHECK_GCC_VERSION(8,1) + GCC_TURN_ON(cast-align=strict) +#endif // 8.1 + GCC_TURN_ON(cast-qual) + GCC_TURN_ON(char-subscripts) +#if CHECK_GCC_VERSION(9,1) + GCC_TURN_ON(chkp) +#endif // 9.1 +#if CHECK_GCC_VERSION(8,1) + GCC_TURN_ON(class-memaccess) +#endif // 8.1 + GCC_TURN_ON(clobbered) +#if CHECK_GCC_VERSION(10,1) + GCC_TURN_ON(comma-subscript) +#endif // 10.1 + GCC_TURN_ON(comment) +#if CHECK_GCC_VERSION(4,9) + GCC_TURN_ON(conditionally-supported) +#endif // 4.9 + GCC_TURN_ON(conversion) + GCC_TURN_ON(ctor-dtor-privacy) +#if CHECK_GCC_VERSION(4,9) + GCC_TURN_ON(date-time) +#endif // 4.9 +#if CHECK_GCC_VERSION(4,7) + GCC_TURN_ON(delete-non-virtual-dtor) +#endif // 4.7 +#if CHECK_GCC_VERSION(9,1) + GCC_TURN_ON(deprecated-copy) +#endif // 9.1 +#if CHECK_GCC_VERSION(9,1) + GCC_TURN_ON(deprecated-copy-dtor) +#endif // 9.1 + GCC_TURN_ON(disabled-optimization) + GCC_TURN_ON(double-promotion) +#if CHECK_GCC_VERSION(7,1) + GCC_TURN_ON(duplicated-branches) +#endif // 7.1 +#if CHECK_GCC_VERSION(6,1) + GCC_TURN_ON(duplicated-cond) +#endif // 6.1 + GCC_TURN_ON(empty-body) + GCC_TURN_ON(endif-labels) + GCC_TURN_ON(enum-compare) +#if CHECK_GCC_VERSION(8,1) + GCC_TURN_ON(extra-semi) +#endif // 8.1 + GCC_TURN_ON(float-equal) + GCC_TURN_ON(format) + GCC_TURN_ON(format-contains-nul) + GCC_TURN_ON(format-extra-args) + GCC_TURN_ON(format-nonliteral) + GCC_TURN_ON(format-security) +#if CHECK_GCC_VERSION(5,1) + GCC_TURN_ON(format-signedness) +#endif // 5.1 +#if CHECK_GCC_VERSION(4,7) + GCC_TURN_ON(format-zero-length) +#endif // 4.7 + GCC_TURN_ON(ignored-qualifiers) + GCC_TURN_ON(init-self) + GCC_TURN_ON(inline) + GCC_TURN_ON(invalid-pch) +#if CHECK_GCC_VERSION(4,8) + GCC_TURN_ON(literal-suffix) +#endif // 4.8 +#if CHECK_GCC_VERSION(6,1) + GCC_TURN_ON(logical-op) +#endif // 6.1 + GCC_TURN_ON(long-long) + GCC_TURN_ON(main) +#if CHECK_GCC_VERSION(4,7) + GCC_TURN_ON(maybe-uninitialized) +#endif // 4.7 +#if CHECK_GCC_VERSION(10,1) + GCC_TURN_ON(mismatched-tags) +#endif // 10.1 + GCC_TURN_ON(missing-braces) + GCC_TURN_ON(missing-declarations) + GCC_TURN_ON(missing-field-initializers) + GCC_TURN_ON(missing-format-attribute) + GCC_TURN_ON(missing-include-dirs) + GCC_TURN_ON(missing-noreturn) + GCC_TURN_ON(multichar) +#if CHECK_GCC_VERSION(6,1) + GCC_TURN_ON(namespaces) +#endif // 6.1 +#if CHECK_GCC_VERSION(4,7) + GCC_TURN_ON(narrowing) +#endif // 4.7 + GCC_TURN_ON(noexcept) +#if CHECK_GCC_VERSION(7,1) + GCC_TURN_ON(noexcept-type) +#endif // 7.1 + GCC_TURN_ON(non-virtual-dtor) +#if CHECK_GCC_VERSION(4,7) + GCC_TURN_ON(nonnull) +#endif // 4.7 +#if CHECK_GCC_VERSION(6,1) + GCC_TURN_ON(null-dereference) +#endif // 6.1 + GCC_TURN_ON(old-style-cast) + GCC_TURN_ON(overlength-strings) + GCC_TURN_ON(overloaded-virtual) + GCC_TURN_ON(packed) + GCC_TURN_ON(packed-bitfield-compat) + GCC_TURN_ON(padded) + GCC_TURN_ON(parentheses) +#if CHECK_GCC_VERSION(9,1) + GCC_TURN_ON(pessimizing-move) +#endif // 9.1 + GCC_TURN_ON(pointer-arith) + GCC_TURN_ON(redundant-decls) +#if CHECK_GCC_VERSION(10,1) + GCC_TURN_ON(redundant-tags) +#endif // 10.1 +#if CHECK_GCC_VERSION(7,1) + GCC_TURN_ON(register) +#endif // 7.1 + GCC_TURN_ON(reorder) +#if CHECK_GCC_VERSION(7,1) + GCC_TURN_ON(restrict) +#endif // 7.1 + GCC_TURN_ON(return-type) + GCC_TURN_ON(sequence-point) + GCC_TURN_ON(shadow) +#if CHECK_GCC_VERSION(6,1) + GCC_TURN_ON(shift-negative-value) +#endif // 6.1 + GCC_TURN_ON(sign-compare) + GCC_TURN_ON(sign-conversion) + GCC_TURN_ON(sign-promo) + GCC_TURN_ON(stack-protector) + GCC_TURN_ON(strict-aliasing) + GCC_TURN_ON(strict-null-sentinel) + GCC_TURN_ON(strict-overflow) +#if CHECK_GCC_VERSION(10,1) + GCC_TURN_ON(string-compare) +#endif // 10.1 +#if CHECK_GCC_VERSION(8,1) + GCC_TURN_ON(stringop-truncation) +#endif // 8.1 +#if CHECK_GCC_VERSION(8,1) + GCC_TURN_ON(suggest-attribute=cold) +#endif // 8.1 + GCC_TURN_ON(suggest-attribute=const) +#if CHECK_GCC_VERSION(4,8) + GCC_TURN_ON(suggest-attribute=format) +#endif // 4.8 +#if CHECK_GCC_VERSION(8,1) + GCC_TURN_ON(suggest-attribute=malloc) +#endif // 8.1 + GCC_TURN_ON(suggest-attribute=noreturn) + GCC_TURN_ON(suggest-attribute=pure) +#if CHECK_GCC_VERSION(5,1) + GCC_TURN_ON(suggest-final-methods) +#endif // 5.1 +#if CHECK_GCC_VERSION(5,1) + GCC_TURN_ON(suggest-final-types) +#endif // 5.1 +#if CHECK_GCC_VERSION(5,1) + GCC_TURN_ON(suggest-override) +#endif // 5.1 + GCC_TURN_ON(switch) + GCC_TURN_ON(switch-default) + GCC_TURN_ON(switch-enum) + GCC_TURN_ON(synth) + GCC_TURN_ON(system-headers) +#if CHECK_GCC_VERSION(6,1) + GCC_TURN_ON(templates) +#endif // 6.1 + GCC_TURN_ON(trampolines) + GCC_TURN_ON(trigraphs) + GCC_TURN_ON(type-limits) + GCC_TURN_ON(undef) + GCC_TURN_ON(uninitialized) + GCC_TURN_ON(unknown-pragmas) + GCC_TURN_ON(unreachable-code) + GCC_TURN_ON(unsafe-loop-optimizations) + GCC_TURN_ON(unused) + GCC_TURN_ON(unused-but-set-parameter) + GCC_TURN_ON(unused-but-set-variable) + GCC_TURN_ON(unused-function) + GCC_TURN_ON(unused-label) +#if CHECK_GCC_VERSION(4,7) + GCC_TURN_ON(unused-local-typedefs) +#endif // 4.7 + GCC_TURN_ON(unused-macros) + GCC_TURN_ON(unused-parameter) + GCC_TURN_ON(unused-value) + GCC_TURN_ON(unused-variable) +#if CHECK_GCC_VERSION(4,8) + GCC_TURN_ON(useless-cast) +#endif // 4.8 + GCC_TURN_ON(variadic-macros) +#if CHECK_GCC_VERSION(4,7) + GCC_TURN_ON(vector-operation-performance) +#endif // 4.7 +#if CHECK_GCC_VERSION(6,1) + GCC_TURN_ON(virtual-inheritance) +#endif // 6.1 + GCC_TURN_ON(vla) +#if CHECK_GCC_VERSION(10,1) + GCC_TURN_ON(volatile) +#endif // 10.1 + GCC_TURN_ON(volatile-register-var) + GCC_TURN_ON(write-strings) +#if CHECK_GCC_VERSION(4,7) + GCC_TURN_ON(zero-as-null-pointer-constant) +#endif // 4.7 + // }}} + + #undef GCC_TURN_ON + + /* + Some warnings still must be disabled, so turn them back off explicitly: + */ + + // Those are potentially useful warnings, but there are just too many + // occurrences of them in our code currently. + GCC_TURN_OFF(conversion) + GCC_TURN_OFF(sign-compare) + GCC_TURN_OFF(sign-conversion) + + GCC_TURN_OFF(old-style-cast) +#if CHECK_GCC_VERSION(4,8) + GCC_TURN_OFF(useless-cast) +#endif // 4.8 + +#if CHECK_GCC_VERSION(10,1) + GCC_TURN_OFF(redundant-tags) // "struct tm" triggers this +#endif // 10.1 + + // This one is given for NULL, and not just literal 0, up to gcc 10, and so + // has to remain disabled for as long as we use any NULLs in our code. +#if CHECK_GCC_VERSION(4,7) && !CHECK_GCC_VERSION(10,1) + GCC_TURN_OFF(zero-as-null-pointer-constant) +#endif + + // wxWARNING_SUPPRESS_MISSING_OVERRIDE() inside wxRTTI macros is just + // ignored by gcc up to 9.x for some reason, so we have no choice but to + // disable it. +#if CHECK_GCC_VERSION(5,1) && !CHECK_GCC_VERSION(9,0) + GCC_TURN_OFF(suggest-override) +#endif + + // The rest are the warnings that we don't ever want to enable. + + // This one is given whenever inheriting from std:: classes without using + // C++11 ABI tag explicitly, probably harmless. +#if CHECK_GCC_VERSION(4,8) + GCC_TURN_OFF(abi-tag) +#endif // 4.8 + + // All those are about using perfectly normal C++ features that are + // actually used in our code. + GCC_TURN_OFF(aggregate-return) + GCC_TURN_OFF(long-long) +#if CHECK_GCC_VERSION(6,1) + GCC_TURN_OFF(namespaces) + GCC_TURN_OFF(multiple-inheritance) + GCC_TURN_OFF(templates) +#endif // 6.1 + + // This warns about missing "default" label in exhaustive switches over + // enums, so it's completely useless. + GCC_TURN_OFF(switch-default) + + // We don't care about padding being added to our structs. + GCC_TURN_OFF(padded) +#endif // gcc >= 4.6 + #if !wxUSE_UTF8_LOCALE_ONLY #define wxNO_IMPLICIT_WXSTRING_ENCODING #endif @@ -20,6 +404,11 @@ #include "allheaders.h" +#ifdef GCC_TURN_OFF + // Just using REQUIRE() below triggers -Wparentheses, so avoid it. + GCC_TURN_OFF(parentheses) +#endif + TEST_CASE("wxNO_IMPLICIT_WXSTRING_ENCODING", "[string]") { wxString s = wxASCII_STR("Hello, ASCII"); From 2f605badf3480e0f0c49aee98039e2ff2a4cd5f4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 25 Aug 2020 23:39:55 +0200 Subject: [PATCH 05/27] Fix g++ 4.8 -Wshadow for parameter/function conflicts Unlike the later versions, g++ 4.8 produces a -Wshadow when the name of a parameter is the same of the name of a method, so rename the (private) parameters to avoid this. --- include/wx/generic/grid.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index 935180d8cf..e46c81536e 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -1140,9 +1140,9 @@ private: { } - wxGridBlocks(iterator_impl begin, iterator_impl end) : - m_begin(begin), - m_end(end) + wxGridBlocks(iterator_impl ibegin, iterator_impl iend) : + m_begin(ibegin), + m_end(iend) { } From 831979ead145b12cf66ffdb6eac10d508bfbbf0d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Aug 2020 18:14:57 +0200 Subject: [PATCH 06/27] Suppress gcc -Wctor-dtor-privacy in wx/strvararg.h Helper structs declared in this header intentionally define their ctor as private, avoid gcc complaints about it. --- include/wx/strvararg.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/wx/strvararg.h b/include/wx/strvararg.h index 3a363a3dee..0abf59b1b3 100644 --- a/include/wx/strvararg.h +++ b/include/wx/strvararg.h @@ -31,6 +31,10 @@ class WXDLLIMPEXP_FWD_BASE wxCStrData; class WXDLLIMPEXP_FWD_BASE wxString; +// There are a lot of structs with intentionally private ctors in this file, +// suppress gcc warnings about this. +wxGCC_WARNING_SUPPRESS(ctor-dtor-privacy) + // ---------------------------------------------------------------------------- // WX_DEFINE_VARARG_FUNC* macros // ---------------------------------------------------------------------------- @@ -1248,4 +1252,6 @@ private: inline void name(_WX_VARARG_FIXED_UNUSED_EXPAND(numfixed, fixed)) \ {} +wxGCC_WARNING_RESTORE(ctor-dtor-privacy) + #endif // _WX_STRVARARG_H_ From 7d74df9a03a98efa759e3c8ffffc7113e18a93e1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Aug 2020 18:16:18 +0200 Subject: [PATCH 07/27] Add wxNOEXCEPT to the hash structs operator() declarations gcc 9 gives -Wnoexcept for these operators and, apparently, not making them noexcept prevents some optimizations in the standard library implementation of unordered_foo<>, so do add it. --- include/wx/hashmap.h | 50 ++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/include/wx/hashmap.h b/include/wx/hashmap.h index 86700f40ca..b1ebc76aaf 100644 --- a/include/wx/hashmap.h +++ b/include/wx/hashmap.h @@ -497,15 +497,15 @@ private: public: wxIntegerHash() { } - size_t operator()( long x ) const { return longHash( x ); } - size_t operator()( unsigned long x ) const { return ulongHash( x ); } - size_t operator()( int x ) const { return intHash( x ); } - size_t operator()( unsigned int x ) const { return uintHash( x ); } - size_t operator()( short x ) const { return shortHash( x ); } - size_t operator()( unsigned short x ) const { return ushortHash( x ); } + size_t operator()( long x ) const wxNOEXCEPT { return longHash( x ); } + size_t operator()( unsigned long x ) const wxNOEXCEPT { return ulongHash( x ); } + size_t operator()( int x ) const wxNOEXCEPT { return intHash( x ); } + size_t operator()( unsigned int x ) const wxNOEXCEPT { return uintHash( x ); } + size_t operator()( short x ) const wxNOEXCEPT { return shortHash( x ); } + size_t operator()( unsigned short x ) const wxNOEXCEPT { return ushortHash( x ); } #ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG - size_t operator()( wxLongLong_t x ) const { return longlongHash(x); } - size_t operator()( wxULongLong_t x ) const { return longlongHash(x); } + size_t operator()( wxLongLong_t x ) const wxNOEXCEPT { return longlongHash(x); } + size_t operator()( wxULongLong_t x ) const wxNOEXCEPT { return longlongHash(x); } #endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG wxIntegerHash& operator=(const wxIntegerHash&) { return *this; } @@ -517,15 +517,15 @@ public: struct WXDLLIMPEXP_BASE wxIntegerHash { wxIntegerHash() { } - unsigned long operator()( long x ) const { return (unsigned long)x; } - unsigned long operator()( unsigned long x ) const { return x; } - unsigned long operator()( int x ) const { return (unsigned long)x; } - unsigned long operator()( unsigned int x ) const { return x; } - unsigned long operator()( short x ) const { return (unsigned long)x; } - unsigned long operator()( unsigned short x ) const { return x; } + unsigned long operator()( long x ) const wxNOEXCEPT { return (unsigned long)x; } + unsigned long operator()( unsigned long x ) const wxNOEXCEPT { return x; } + unsigned long operator()( int x ) const wxNOEXCEPT { return (unsigned long)x; } + unsigned long operator()( unsigned int x ) const wxNOEXCEPT { return x; } + unsigned long operator()( short x ) const wxNOEXCEPT { return (unsigned long)x; } + unsigned long operator()( unsigned short x ) const wxNOEXCEPT { return x; } #ifdef wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG - wxULongLong_t operator()( wxLongLong_t x ) const { return static_cast(x); } - wxULongLong_t operator()( wxULongLong_t x ) const { return x; } + wxULongLong_t operator()( wxLongLong_t x ) const wxNOEXCEPT { return static_cast(x); } + wxULongLong_t operator()( wxULongLong_t x ) const wxNOEXCEPT { return x; } #endif // wxHAS_LONG_LONG_T_DIFFERENT_FROM_LONG }; @@ -552,27 +552,27 @@ struct WXDLLIMPEXP_BASE wxPointerHash wxPointerHash() { } #ifdef wxNEEDS_WX_HASH_MAP - wxUIntPtr operator()( const void* k ) const { return wxPtrToUInt(k); } + wxUIntPtr operator()( const void* k ) const wxNOEXCEPT { return wxPtrToUInt(k); } #else - size_t operator()( const void* k ) const { return (size_t)k; } + size_t operator()( const void* k ) const wxNOEXCEPT { return (size_t)k; } #endif }; struct WXDLLIMPEXP_BASE wxPointerEqual { wxPointerEqual() { } - bool operator()( const void* a, const void* b ) const { return a == b; } + bool operator()( const void* a, const void* b ) const wxNOEXCEPT { return a == b; } }; // wxString, char*, wchar_t* struct WXDLLIMPEXP_BASE wxStringHash { wxStringHash() {} - unsigned long operator()( const wxString& x ) const + unsigned long operator()( const wxString& x ) const wxNOEXCEPT { return stringHash( x.wx_str() ); } - unsigned long operator()( const wchar_t* x ) const + unsigned long operator()( const wchar_t* x ) const wxNOEXCEPT { return stringHash( x ); } - unsigned long operator()( const char* x ) const + unsigned long operator()( const char* x ) const wxNOEXCEPT { return stringHash( x ); } #if WXWIN_COMPATIBILITY_2_8 @@ -591,12 +591,12 @@ struct WXDLLIMPEXP_BASE wxStringHash struct WXDLLIMPEXP_BASE wxStringEqual { wxStringEqual() {} - bool operator()( const wxString& a, const wxString& b ) const + bool operator()( const wxString& a, const wxString& b ) const wxNOEXCEPT { return a == b; } - bool operator()( const wxChar* a, const wxChar* b ) const + bool operator()( const wxChar* a, const wxChar* b ) const wxNOEXCEPT { return wxStrcmp( a, b ) == 0; } #if wxUSE_UNICODE - bool operator()( const char* a, const char* b ) const + bool operator()( const char* a, const char* b ) const wxNOEXCEPT { return strcmp( a, b ) == 0; } #endif // wxUSE_UNICODE }; From 3c628138f570f363009299be65c3992e293580e1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Aug 2020 18:17:44 +0200 Subject: [PATCH 08/27] Suppress bogus -Wnoexcept from gcc9 in wx/graphics.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Due to what looks like a bug, gcc 9.3.0 gives the following incomplete error message without it: include/wx/graphics.h:278:7: error: but ‘wxGraphicsGradientStop::wxGraphicsGradientStop(wxGraphicsGradientStop&&)’ does not throw; perhaps it should be declared ‘noexcept’ [-Werror=noexcept] (without any other diagnostics). --- include/wx/graphics.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/wx/graphics.h b/include/wx/graphics.h index be0bfcbccc..1320a22cf4 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -274,6 +274,12 @@ extern WXDLLIMPEXP_DATA_CORE(wxGraphicsMatrix) wxNullGraphicsMatrix; // and how they are spread out in a gradient // ---------------------------------------------------------------------------- +// gcc 9 gives a nonsensical warning about implicitly generated move ctor not +// throwing but not being noexcept, suppress it. +#if wxCHECK_GCC_VERSION(9, 1) && !wxCHECK_GCC_VERSION(10, 0) +wxGCC_WARNING_SUPPRESS(noexcept) +#endif + // Describes a single gradient stop. class wxGraphicsGradientStop { @@ -306,6 +312,10 @@ private: float m_pos; }; +#if wxCHECK_GCC_VERSION(9, 1) && !wxCHECK_GCC_VERSION(10, 0) +wxGCC_WARNING_RESTORE(noexcept) +#endif + // A collection of gradient stops ordered by their positions (from lowest to // highest). The first stop (index 0, position 0.0) is always the starting // colour and the last one (index GetCount() - 1, position 1.0) is the end From 1861065ef271084ade87fdf98732463786beae26 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Aug 2020 19:14:32 +0200 Subject: [PATCH 09/27] Disable -Wformat in system headers This is given for the use of %zu by gcc 5.4. --- tests/allheaders.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/allheaders.cpp b/tests/allheaders.cpp index 510f858495..5d2f434134 100644 --- a/tests/allheaders.cpp +++ b/tests/allheaders.cpp @@ -42,6 +42,7 @@ GCC_TURN_OFF(aggregate-return) GCC_TURN_OFF(conversion) + GCC_TURN_OFF(format) GCC_TURN_OFF(padded) GCC_TURN_OFF(parentheses) GCC_TURN_OFF(sign-compare) From 266c3a962fb4a8f5a3d2838e99b1156736ce638b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Aug 2020 19:17:34 +0200 Subject: [PATCH 10/27] Disable -Winline as we can't ensure all functions are inlined It doesn't really make sense to enable this for C++ code, with a lot of implicitly inline functions. --- tests/allheaders.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/allheaders.cpp b/tests/allheaders.cpp index 5d2f434134..cb3a6e3b67 100644 --- a/tests/allheaders.cpp +++ b/tests/allheaders.cpp @@ -379,6 +379,10 @@ GCC_TURN_OFF(abi-tag) #endif // 4.8 + // This can be used to ask the compiler to explain why some function is not + // inlined, but it's perfectly normal for some functions not to be inlined. + GCC_TURN_OFF(inline) + // All those are about using perfectly normal C++ features that are // actually used in our code. GCC_TURN_OFF(aggregate-return) From ca7fcfe9c3fe7f2c1944ba6beb1d21d2de5047cb Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Aug 2020 20:58:30 +0200 Subject: [PATCH 11/27] Add wxGCC_ONLY_WARNING_{SUPPRESS,RESTORE} macros When the original wxGCC_WARNING_SUPPRESS was added, clang understood all gcc warnings, so it made sense to also apply it when building with clang, but recent gcc versions have added warnings not available in clang any more, so we now need a macro for disabling warning the warnings for gcc only. Perhaps we should rename the existing wxGCC_XXX macros to use wxGCC_OR_CLANG prefix. --- include/wx/defs.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/wx/defs.h b/include/wx/defs.h index 804e828b74..cb1d495b80 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -662,6 +662,9 @@ typedef short int WXTYPE; wxGCC_WARNING_SUPPRESS(float-equal) inline bool wxIsSameDouble(double x, double y) { return x == y; } wxGCC_WARNING_RESTORE(float-equal) + + Note that these macros apply to both gcc and clang, even though they only + have "GCC" in their names. */ #if defined(__clang__) || wxCHECK_GCC_VERSION(4, 6) # define wxGCC_WARNING_SUPPRESS(x) \ @@ -674,6 +677,17 @@ typedef short int WXTYPE; # define wxGCC_WARNING_RESTORE(x) #endif +/* + Similar macros but for gcc-specific warnings. + */ +#ifdef __GNUC__ +# define wxGCC_ONLY_WARNING_SUPPRESS(x) wxGCC_WARNING_SUPPRESS(x) +# define wxGCC_ONLY_WARNING_RESTORE(x) wxGCC_WARNING_RESTORE(x) +#else +# define wxGCC_ONLY_WARNING_SUPPRESS(x) +# define wxGCC_ONLY_WARNING_RESTORE(x) +#endif + /* Specific macros for -Wcast-function-type warning new in gcc 8. */ #if wxCHECK_GCC_VERSION(8, 0) #define wxGCC_WARNING_SUPPRESS_CAST_FUNCTION_TYPE() \ From dca6f310bb56fc54b8e2ef888694b38dfd9cd21a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Aug 2020 21:05:43 +0200 Subject: [PATCH 12/27] Replace C-style cast with const_cast<> in wxUniv Don't use C casts to remove const-ness (avoids gcc -Wcast-qual). --- include/wx/univ/control.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/wx/univ/control.h b/include/wx/univ/control.h index 8a623da0ed..f6b4f66645 100644 --- a/include/wx/univ/control.h +++ b/include/wx/univ/control.h @@ -79,7 +79,10 @@ public: return m_indexAccel == -1 ? wxT('\0') : (wxChar)m_label[m_indexAccel]; } - virtual wxWindow *GetInputWindow() const wxOVERRIDE { return (wxWindow*)this; } + virtual wxWindow *GetInputWindow() const wxOVERRIDE + { + return const_cast(this); + } protected: // common part of all ctors From 9206a9de00c87751f414e7c60a8efd845df7cf30 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Aug 2020 21:09:36 +0200 Subject: [PATCH 13/27] Remove trailing semicolon from wxDFB_DECLARE_INTERFACE() This avoids -Wpedantic warnings when a semicolon is used after it. --- include/wx/dfb/dfbptr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/wx/dfb/dfbptr.h b/include/wx/dfb/dfbptr.h index e34e3dc268..0d442b8ebc 100644 --- a/include/wx/dfb/dfbptr.h +++ b/include/wx/dfb/dfbptr.h @@ -23,7 +23,7 @@ */ #define wxDFB_DECLARE_INTERFACE(name) \ class wx##name; \ - typedef wxDfbPtr wx##name##Ptr; + typedef wxDfbPtr wx##name##Ptr //----------------------------------------------------------------------------- From 9c48b0e8e72b4f7842a78c56039961c4d08c7df0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Aug 2020 21:14:45 +0200 Subject: [PATCH 14/27] Remove redundant wxSetCursor() declarations Avoid -Wredundant-decls from gcc by not duplicating the declaration from wx/gdicmn.h in wx/*/cursor.h. --- include/wx/motif/cursor.h | 2 -- include/wx/osx/cursor.h | 2 -- 2 files changed, 4 deletions(-) diff --git a/include/wx/motif/cursor.h b/include/wx/motif/cursor.h index 0658abc6ec..e59521a7c2 100644 --- a/include/wx/motif/cursor.h +++ b/include/wx/motif/cursor.h @@ -63,7 +63,5 @@ private: wxDECLARE_DYNAMIC_CLASS(wxCursor); }; -extern WXDLLIMPEXP_CORE void wxSetCursor(const wxCursor& cursor); - #endif // _WX_CURSOR_H_ diff --git a/include/wx/osx/cursor.h b/include/wx/osx/cursor.h index 37e221f6ce..ae3eb2463a 100644 --- a/include/wx/osx/cursor.h +++ b/include/wx/osx/cursor.h @@ -47,6 +47,4 @@ private: wxDECLARE_DYNAMIC_CLASS(wxCursor); }; -extern WXDLLIMPEXP_CORE void wxSetCursor(const wxCursor& cursor); - #endif // _WX_CURSOR_H_ From 9c2cf912238de8f29f8e10df820487aa9b8fd9cc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Aug 2020 21:16:43 +0200 Subject: [PATCH 15/27] Don't remove const-ness using C-style cast Avoid another -Wcast-qual from gcc. --- include/wx/motif/statbmp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/wx/motif/statbmp.h b/include/wx/motif/statbmp.h index f63fadab50..4d0bbf09df 100644 --- a/include/wx/motif/statbmp.h +++ b/include/wx/motif/statbmp.h @@ -52,7 +52,7 @@ public: wxIcon GetIcon() const { // don't use wxDynamicCast, icons and bitmaps are really the same thing - return *(wxIcon*)&m_messageBitmap; + return *(const wxIcon*)&m_messageBitmap; } // for compatibility with wxMSW From 3bbefcdd743a303f8cad4ae75d493e9d341d5382 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Aug 2020 21:18:27 +0200 Subject: [PATCH 16/27] Don't trigger warnings in standard headers when building wxQt Pre-include QFont header in wxQt to avoid warnings for the other headers included from it. --- tests/allheaders.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/allheaders.cpp b/tests/allheaders.cpp index cb3a6e3b67..192eb91b75 100644 --- a/tests/allheaders.cpp +++ b/tests/allheaders.cpp @@ -84,6 +84,10 @@ #include "catch.hpp" +#if defined(__WXQT__) + #include +#endif + #ifdef GCC_TURN_OFF #pragma GCC diagnostic pop #endif From 19bc293086e7334585d65fcdd0b7ca2c13c9f013 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Aug 2020 22:00:47 +0200 Subject: [PATCH 17/27] Remove extraneous semicolon in wx/qt/menuitem.h Avoid -Wpedantic from gcc. --- include/wx/qt/menuitem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/wx/qt/menuitem.h b/include/wx/qt/menuitem.h index 24e5e27003..5f507f01f9 100644 --- a/include/wx/qt/menuitem.h +++ b/include/wx/qt/menuitem.h @@ -36,7 +36,7 @@ public: virtual bool IsChecked() const wxOVERRIDE; virtual void SetBitmap(const wxBitmap& bitmap); - virtual const wxBitmap& GetBitmap() const { return m_bitmap; }; + virtual const wxBitmap& GetBitmap() const { return m_bitmap; } virtual QAction *GetHandle() const; From 9f63592eba9afa68913a4602c8768fb5378c5847 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Aug 2020 22:01:08 +0200 Subject: [PATCH 18/27] Remove unnecessary wxBitmap copy ctor from wxQt This ctor is not needed as the inherited wxObject ctor is sufficient and defining it but not operator=() explicitly results in -Wdeprecated-copy from gcc 10. --- include/wx/qt/bitmap.h | 1 - src/qt/bitmap.cpp | 5 ----- 2 files changed, 6 deletions(-) diff --git a/include/wx/qt/bitmap.h b/include/wx/qt/bitmap.h index 0505d4c3f6..b8eeb57ad5 100644 --- a/include/wx/qt/bitmap.h +++ b/include/wx/qt/bitmap.h @@ -22,7 +22,6 @@ class WXDLLIMPEXP_CORE wxBitmap : public wxBitmapBase public: wxBitmap(); wxBitmap(QPixmap pix); - wxBitmap(const wxBitmap& bmp); wxBitmap(const char bits[], int width, int height, int depth = 1); wxBitmap(int width, int height, int depth = wxBITMAP_SCREEN_DEPTH); wxBitmap(const wxSize& sz, int depth = wxBITMAP_SCREEN_DEPTH); diff --git a/src/qt/bitmap.cpp b/src/qt/bitmap.cpp index 28c5d2d30a..4d8ec0638a 100644 --- a/src/qt/bitmap.cpp +++ b/src/qt/bitmap.cpp @@ -174,11 +174,6 @@ wxBitmap::wxBitmap(QPixmap pix) m_refData = new wxBitmapRefData(pix); } -wxBitmap::wxBitmap(const wxBitmap& bmp) -{ - Ref(bmp); -} - wxBitmap::wxBitmap(const char bits[], int width, int height, int depth ) { wxASSERT(depth == 1); From 7352a2879c242cc32fa134082ba031919b779e95 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Aug 2020 22:03:47 +0200 Subject: [PATCH 19/27] Rename Qt-specific GetEventType() to start with "Qt" prefix This avoids conflicts with another method with the same name defined in generic wxGenericFileDirButton, which must neither override nor hide this method of wxButton. --- include/wx/qt/anybutton.h | 2 +- include/wx/qt/button.h | 2 +- include/wx/qt/tglbtn.h | 2 +- src/qt/anybutton.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/wx/qt/anybutton.h b/include/wx/qt/anybutton.h index 85a8bb9cbe..23f409c8bd 100644 --- a/include/wx/qt/anybutton.h +++ b/include/wx/qt/anybutton.h @@ -29,7 +29,7 @@ public: // implementation only void QtUpdateState(); - virtual int GetEventType() const = 0; + virtual int QtGetEventType() const = 0; protected: virtual wxBitmap DoGetBitmap(State state) const wxOVERRIDE; diff --git a/include/wx/qt/button.h b/include/wx/qt/button.h index 06cfb10876..efc17c646d 100644 --- a/include/wx/qt/button.h +++ b/include/wx/qt/button.h @@ -32,7 +32,7 @@ public: virtual wxWindow *SetDefault() wxOVERRIDE; // implementation only - virtual int GetEventType() const wxOVERRIDE { return wxEVT_BUTTON; } + virtual int QtGetEventType() const wxOVERRIDE { return wxEVT_BUTTON; } private: wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxButton); diff --git a/include/wx/qt/tglbtn.h b/include/wx/qt/tglbtn.h index 3d1d7a64d0..936669425a 100644 --- a/include/wx/qt/tglbtn.h +++ b/include/wx/qt/tglbtn.h @@ -36,7 +36,7 @@ public: virtual bool GetValue() const wxOVERRIDE; // implementation only - virtual int GetEventType() const wxOVERRIDE { return wxEVT_TOGGLEBUTTON; } + virtual int QtGetEventType() const wxOVERRIDE { return wxEVT_TOGGLEBUTTON; } private: wxDECLARE_DYNAMIC_CLASS(wxToggleButton); diff --git a/src/qt/anybutton.cpp b/src/qt/anybutton.cpp index 5c6f880c6b..6a5f142b4f 100644 --- a/src/qt/anybutton.cpp +++ b/src/qt/anybutton.cpp @@ -45,7 +45,7 @@ void wxQtPushButton::clicked(bool checked) wxAnyButton *handler = GetHandler(); if ( handler ) { - wxCommandEvent event( handler->GetEventType(), handler->GetId() ); + wxCommandEvent event( handler->QtGetEventType(), handler->GetId() ); if ( isCheckable() ) // toggle buttons { event.SetInt(checked); From 36c5884acb357871d089217bafcf3f7a2fb591ee Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Aug 2020 22:26:34 +0200 Subject: [PATCH 20/27] Generalize WX_ATTRIBUTE_PRINTF to WX_ATTRIBUTE_FORMAT Allow applying gcc "format" attribute to other functions and do apply it to wxStrftime(). Also suppress -Wformat-nonliteral inside wxStrftime() itself, as it's now supposed to be checked when calling it. --- include/wx/defs.h | 12 +++++++----- include/wx/wxcrt.h | 9 ++++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/wx/defs.h b/include/wx/defs.h index cb1d495b80..83bae9dca3 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -542,12 +542,14 @@ typedef short int WXTYPE; /* ---------------------------------------------------------------------------- */ /* Printf-like attribute definitions to obtain warnings with GNU C/C++ */ +#if defined(__GNUC__) && !wxUSE_UNICODE +# define WX_ATTRIBUTE_FORMAT(like, m, n) __attribute__ ((__format__ (like, m, n))) +#else +# define WX_ATTRIBUTE_FORMAT(like, m, n) +#endif + #ifndef WX_ATTRIBUTE_PRINTF -# if defined(__GNUC__) && !wxUSE_UNICODE -# define WX_ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) -# else -# define WX_ATTRIBUTE_PRINTF(m, n) -# endif +# define WX_ATTRIBUTE_PRINTF(m, n) WX_ATTRIBUTE_FORMAT(__printf__, m, n) # define WX_ATTRIBUTE_PRINTF_1 WX_ATTRIBUTE_PRINTF(1, 2) # define WX_ATTRIBUTE_PRINTF_2 WX_ATTRIBUTE_PRINTF(2, 3) diff --git a/include/wx/wxcrt.h b/include/wx/wxcrt.h index 6cf08f4fde..d4d6cd7df4 100644 --- a/include/wx/wxcrt.h +++ b/include/wx/wxcrt.h @@ -1052,9 +1052,16 @@ inline wchar_t* wxGetenv(const wxScopedWCharBuffer& name) { return wxCRT_GetenvW // ---------------------------------------------------------------------------- #ifndef wxNO_IMPLICIT_WXSTRING_ENCODING +WX_ATTRIBUTE_FORMAT(__strftime__, 3, 4) inline size_t wxStrftime(char *s, size_t max, const wxString& format, const struct tm *tm) - { return wxCRT_StrftimeA(s, max, format.mb_str(), tm); } + { + wxGCC_ONLY_WARNING_SUPPRESS(format-nonliteral) + + return wxCRT_StrftimeA(s, max, format.mb_str(), tm); + + wxGCC_ONLY_WARNING_RESTORE(format-nonliteral) + } #endif // wxNO_IMPLICIT_WXSTRING_ENCODING inline size_t wxStrftime(wchar_t *s, size_t max, From 24914ec7dfa6bcfaebad96deae9df8d81d9be7ba Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Aug 2020 22:29:17 +0200 Subject: [PATCH 21/27] Suppress unavoidable -Wformat-literal in wx[F]printf() Disable gcc format string checks inside these functions. --- include/wx/wxcrtvararg.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/wx/wxcrtvararg.h b/include/wx/wxcrtvararg.h index 4d998df14f..38bbb241c2 100644 --- a/include/wx/wxcrtvararg.h +++ b/include/wx/wxcrtvararg.h @@ -276,6 +276,8 @@ #endif +wxGCC_ONLY_WARNING_SUPPRESS(format-nonliteral) + WX_DEFINE_VARARG_FUNC_SANS_N0(int, wxPrintf, 1, (const wxFormatString&), wxCRT_PrintfNative, wxCRT_PrintfA) inline int wxPrintf(const wxFormatString& s) @@ -290,6 +292,8 @@ inline int wxFprintf(FILE *f, const wxFormatString& s) return wxFprintf(f, wxASCII_STR("%s"), s.InputAsString()); } +wxGCC_ONLY_WARNING_RESTORE(format-nonliteral) + // va_list versions of printf functions simply forward to the respective // CRT function; note that they assume that va_list was created using // wxArgNormalizer! From a535d2c64d56462f2935c59bd8e5ec02013dc684 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Aug 2020 23:44:09 +0200 Subject: [PATCH 22/27] Suppress -Wnull-dereference in wxString::GetCacheElement() It doesn't seem to be really possible here. --- include/wx/string.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/wx/string.h b/include/wx/string.h index eb54eb24c7..ab0a72b737 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -569,6 +569,12 @@ private: // its corresponding index in the byte string or not Cache::Element *GetCacheElement() const { + // gcc warns about cacheBegin and c inside the loop being possibly null, + // but this shouldn't actually be the case +#if wxCHECK_GCC_VERSION(6,1) + wxGCC_ONLY_WARNING_SUPPRESS(null-dereference) +#endif + Cache::Element * const cacheBegin = GetCacheBegin(); Cache::Element * const cacheEnd = GetCacheEnd(); Cache::Element * const cacheStart = cacheBegin + LastUsedCacheElement(); @@ -598,6 +604,10 @@ private: } return c; + +#if wxCHECK_GCC_VERSION(6,1) + wxGCC_ONLY_WARNING_RESTORE(null-dereference) +#endif } size_t DoPosToImpl(size_t pos) const From 3fc5d134a3c5387f1b6061fdcab6b7146c579ad5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Aug 2020 23:51:12 +0200 Subject: [PATCH 23/27] Suppress strange -Wunsafe-loop-optimizations in wxString code The error message wx/string.h:558:47: error: missed loop optimization, the loop counter may overflow [-Werror=unsafe-loop-optimizations] for ( Cache::Element *c = cacheBegin; c != cacheEnd; c++ ) ~~^~~~~~~~~~~ doesn't seem to really make much sense, as it shouldn't overflow here. --- include/wx/string.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/wx/string.h b/include/wx/string.h index ab0a72b737..2dc071290a 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -554,6 +554,12 @@ private: if ( cacheBegin == NULL ) return NULL; #endif + + // gcc 7 warns about not being able to optimize this loop because of + // possible loop variable overflow, really not sure what to do about + // this, so just disable this warnings for now + wxGCC_ONLY_WARNING_SUPPRESS(unsafe-loop-optimizations) + Cache::Element * const cacheEnd = GetCacheEnd(); for ( Cache::Element *c = cacheBegin; c != cacheEnd; c++ ) { @@ -561,6 +567,8 @@ private: return c; } + wxGCC_ONLY_WARNING_RESTORE(unsafe-loop-optimizations) + return NULL; } From 6f9390306dcdccd1478eca6febebc4af4c42377d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Aug 2020 23:52:32 +0200 Subject: [PATCH 24/27] Disable -Wsuggest-final-xxx in the headers for now We don't use "final" in our code, as very few classes in wx code have virtual functions but are not meant to be derived from in the user code. Ideal would be to check the existing warnings and maybe apply "final" if it's relevant and disable it otherwise, as these warnings can be useful to build the application code with, but for now just disable them in the test suite. --- tests/allheaders.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/allheaders.cpp b/tests/allheaders.cpp index 192eb91b75..51a20cab45 100644 --- a/tests/allheaders.cpp +++ b/tests/allheaders.cpp @@ -368,6 +368,13 @@ GCC_TURN_OFF(zero-as-null-pointer-constant) #endif + // These ones could be useful to explore, but for now we don't use "final" + // at all anywhere. +#if CHECK_GCC_VERSION(5,1) + GCC_TURN_OFF(suggest-final-methods) + GCC_TURN_OFF(suggest-final-types) +#endif // 5.1 + // wxWARNING_SUPPRESS_MISSING_OVERRIDE() inside wxRTTI macros is just // ignored by gcc up to 9.x for some reason, so we have no choice but to // disable it. From 03bc49de2d600d5847a5f217bdc6cde1d5d4c19a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 31 Aug 2020 01:20:03 +0200 Subject: [PATCH 25/27] Include before enabling all the warnings This avoids tons of -Wredundant-decls and -Wnon-virtual-dtor (given for all OLE interfaces). --- tests/allheaders.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/allheaders.cpp b/tests/allheaders.cpp index 51a20cab45..25ccd5b2e7 100644 --- a/tests/allheaders.cpp +++ b/tests/allheaders.cpp @@ -84,7 +84,9 @@ #include "catch.hpp" -#if defined(__WXQT__) +#if defined(__WXMSW__) + #include +#elif defined(__WXQT__) #include #endif From 8b7ddbd0acc4fa5c938cd06b7a659a53a6c9e8e8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 31 Aug 2020 01:23:13 +0200 Subject: [PATCH 26/27] Use wxOVERRIDE for wxStackWalker and wxStackFrame in wxMSW Thanks gcc for -Wsuggest-override. --- include/wx/msw/stackwalk.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/wx/msw/stackwalk.h b/include/wx/msw/stackwalk.h index 072a49b464..f76e76f52c 100644 --- a/include/wx/msw/stackwalk.h +++ b/include/wx/msw/stackwalk.h @@ -49,21 +49,21 @@ public: m_addrFrame = addrFrame; } - virtual size_t GetParamCount() const + virtual size_t GetParamCount() const wxOVERRIDE { ConstCast()->OnGetParam(); return DoGetParamCount(); } virtual bool - GetParam(size_t n, wxString *type, wxString *name, wxString *value) const; + GetParam(size_t n, wxString *type, wxString *name, wxString *value) const wxOVERRIDE; // callback used by OnGetParam(), don't call directly void OnParam(wxSYMBOL_INFO *pSymInfo); protected: - virtual void OnGetName(); - virtual void OnGetLocation(); + virtual void OnGetName() wxOVERRIDE; + virtual void OnGetLocation() wxOVERRIDE; void OnGetParam(); @@ -96,9 +96,9 @@ public: // only wxStackWalker(const char * WXUNUSED(argv0) = NULL) { } - virtual void Walk(size_t skip = 1, size_t maxDepth = wxSTACKWALKER_MAX_DEPTH); + virtual void Walk(size_t skip = 1, size_t maxDepth = wxSTACKWALKER_MAX_DEPTH) wxOVERRIDE; #if wxUSE_ON_FATAL_EXCEPTION - virtual void WalkFromException(size_t maxDepth = wxSTACKWALKER_MAX_DEPTH); + virtual void WalkFromException(size_t maxDepth = wxSTACKWALKER_MAX_DEPTH) wxOVERRIDE; #endif // wxUSE_ON_FATAL_EXCEPTION From 2a17eef2edb18409038db54f8772b222e798b939 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 31 Aug 2020 12:40:12 +0200 Subject: [PATCH 27/27] Pre-include even more standard headers with MinGW/Cygwin Avoid -Wredundant-decls when including them later by pre-including them before enabling this warning. --- tests/allheaders.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/allheaders.cpp b/tests/allheaders.cpp index 25ccd5b2e7..6003970d65 100644 --- a/tests/allheaders.cpp +++ b/tests/allheaders.cpp @@ -86,6 +86,14 @@ #if defined(__WXMSW__) #include + + // Avoid warnings about redeclaring standard functions such as chmod() in + // various standard headers when using MinGW/Cygwin. + #if defined(__MINGW32__) || defined(__CYGWIN__) + #include + #include + #include + #endif #elif defined(__WXQT__) #include #endif