From a0ea27cccfc7c2198c8a3ded7c9828fdac624c45 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 17 Apr 2023 18:30:32 +0200 Subject: [PATCH 1/5] Restrict check for obsolete macros to C++ code Only check for the use of NULL in C++ code, not C, for example, where it still can, and should, be used. Also allow using "NULL" as part of a larger macro name (where it would be followed by "_") or at the beginning/end of a string. --- .github/workflows/code_checks.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code_checks.yml b/.github/workflows/code_checks.yml index 065271f877..d3ce8b644c 100644 --- a/.github/workflows/code_checks.yml +++ b/.github/workflows/code_checks.yml @@ -87,8 +87,8 @@ jobs: run: | git fetch --depth=1 origin master if git diff origin/master \ - ':!.github/workflows/code_checks.yml' \ - | grep -E '^\+.*(wxOVERRIDE|wxNOEXCEPT|[^_@]NULL)'; then + ':**.h' ':**.cpp' \ + | grep -E '^\+.*(wxOVERRIDE|wxNOEXCEPT|[^"_@]NULL[^"_])'; then echo "::error ::Please use C++11 equivalents of the deprecated macros in the new code." exit 1 fi From 9935a29c7f7f7e498c8cc2c137e5ab960b0029fc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 17 Apr 2023 18:36:33 +0200 Subject: [PATCH 2/5] Stop using "NULL" in the minimal sample This should have been part of 4f4c5fcfdf (Use nullptr instead of NULL in the code and documentation, 2022-10-16). --- samples/minimal/minimal.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp index 501caf9096..5f32257c6b 100644 --- a/samples/minimal/minimal.cpp +++ b/samples/minimal/minimal.cpp @@ -139,7 +139,7 @@ bool MyApp::OnInit() // frame constructor MyFrame::MyFrame(const wxString& title) - : wxFrame(NULL, wxID_ANY, title) + : wxFrame(nullptr, wxID_ANY, title) { // set the frame icon SetIcon(wxICON(sample)); From f27a7c5d00fa4b5c965d1ec47e4a69285081909a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 17 Apr 2023 18:37:17 +0200 Subject: [PATCH 3/5] Use nullptr instead of NULL in Unix wxStackWalker code Another place which should have been updated in 4f4c5fcfdf (Use nullptr instead of NULL in the code and documentation, 2022-10-16) but wasn't. --- src/unix/stackwalk.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/unix/stackwalk.cpp b/src/unix/stackwalk.cpp index 95a0dfdd59..99dac840cb 100644 --- a/src/unix/stackwalk.cpp +++ b/src/unix/stackwalk.cpp @@ -308,7 +308,7 @@ struct ModuleInfo { } - // Name of the file containing this address, may be NULL. + // Name of the file containing this address, may be null. const char* name; // Difference between the address in the file and in memory. @@ -322,7 +322,7 @@ ModuleInfo GetModuleInfoFromAddr(void* addr) if ( !dladdr1(addr, &info, (void**)&lm, RTLD_DL_LINKMAP) ) { // Probably not worth spamming the user with even debug errors. - return ModuleInfo(NULL, 0); + return ModuleInfo(nullptr, 0); } return ModuleInfo(info.dli_fname, lm->l_addr); From d03fc649ab56d6bda2d4e10a327a363e9098d45d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 17 Apr 2023 18:38:03 +0200 Subject: [PATCH 4/5] Generate code using nullptr instead of NULL in wxrc There doesn't seem to be any reason to keep compatibility with C++98 here, so use nullptr for consistency. --- utils/wxrc/wxrc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/wxrc/wxrc.cpp b/utils/wxrc/wxrc.cpp index 137e6978eb..9c9e6ad72c 100644 --- a/utils/wxrc/wxrc.cpp +++ b/utils/wxrc/wxrc.cpp @@ -171,7 +171,7 @@ public: m_className + wxT("(") + *m_ancestorClassNames.begin() + - wxT(" *parent=NULL){\n") + + wxT(" *parent=nullptr){\n") + wxT(" InitWidgetsFromXRC((wxWindow *)parent);\n") wxT(" }\n") wxT("};\n") @@ -180,7 +180,7 @@ public: else { file.Write(m_className + wxT("(){\n") + - wxT(" InitWidgetsFromXRC(NULL);\n") + wxT(" InitWidgetsFromXRC(nullptr);\n") wxT(" }\n") wxT("};\n")); From 9a52a15e26e7db0215ecd9bc28f795af4b6a5fba Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 17 Apr 2023 18:43:02 +0200 Subject: [PATCH 5/5] Initialize wxWeakRef members in their declarations Instead of doing it in all ctors initializer lists. No real changes. --- include/wx/weakref.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/wx/weakref.h b/include/wx/weakref.h index d8e16358c4..754b804400 100644 --- a/include/wx/weakref.h +++ b/include/wx/weakref.h @@ -31,11 +31,11 @@ public: typedef T element_type; // Default ctor - wxWeakRef() : m_pobj(nullptr), m_ptbase(nullptr) { } + wxWeakRef() = default; // Ctor from the object of this type: this is needed as the template ctor // below is not used by at least g++4 when a literal NULL is used - wxWeakRef(T *pobj) : m_pobj(nullptr), m_ptbase(nullptr) + wxWeakRef(T *pobj) { this->Assign(pobj); } @@ -43,14 +43,14 @@ public: // When we have the full type here, static_cast<> will always work // (or give a straight compiler error). template - wxWeakRef(TDerived* pobj) : m_pobj(nullptr), m_ptbase(nullptr) + wxWeakRef(TDerived* pobj) { this->Assign(pobj); } // We need this copy ctor, since otherwise a default compiler (binary) copy // happens (if embedded as an object member). - wxWeakRef(const wxWeakRef& wr) : m_pobj(nullptr), m_ptbase(nullptr) + wxWeakRef(const wxWeakRef& wr) { this->Assign(wr.get()); } @@ -124,8 +124,8 @@ protected: } } - T *m_pobj; - wxTrackable *m_ptbase; + T *m_pobj = nullptr; + wxTrackable *m_ptbase = nullptr; }; @@ -137,7 +137,7 @@ template class wxWeakRefDynamic : public wxTrackerNode { public: - wxWeakRefDynamic() : m_pobj(nullptr) { } + wxWeakRefDynamic() = default; wxWeakRefDynamic(T* pobj) : m_pobj(pobj) { @@ -209,7 +209,7 @@ protected: } } - T *m_pobj; + T *m_pobj = nullptr; }; #endif // RTTI enabled