https://trac.wxwidgets.org/ticket/18355 https://github.com/wxWidgets/wxWidgets/pull/1252.diff From b5e3ac742101c20668c8f802f4f32474af2d5e5b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 8 Mar 2019 16:13:00 +0100 Subject: [PATCH] Add support for passing nullptr to wx pseudo-vararg functions Allow passing literal nullptr as an argument corresponding to "%p" in the format string. Closes #18355. --- include/wx/strvararg.h | 6 ++++++ tests/strings/vararg.cpp | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/include/wx/strvararg.h b/include/wx/strvararg.h index 57429045d4a..7d7afb58a7b 100644 --- include/wx/strvararg.h +++ include/wx/strvararg.h @@ -436,6 +436,12 @@ wxFORMAT_STRING_SPECIFIER(int*, wxFormatString::Arg_IntPtr | wxFormatString::Arg wxFORMAT_STRING_SPECIFIER(short int*, wxFormatString::Arg_ShortIntPtr | wxFormatString::Arg_Pointer) wxFORMAT_STRING_SPECIFIER(long int*, wxFormatString::Arg_LongIntPtr | wxFormatString::Arg_Pointer) +// Support for nullptr is available since MSVS 2010, even though it doesn't +// define __cplusplus as a C++11 compiler. +#if __cplusplus >= 201103 || wxCHECK_VISUALC_VERSION(10) +wxFORMAT_STRING_SPECIFIER(nullptr_t, wxFormatString::Arg_Pointer) +#endif + #undef wxFORMAT_STRING_SPECIFIER diff --git a/tests/strings/vararg.cpp b/tests/strings/vararg.cpp index 14eaa88333e..413cb2e4c69 100644 --- tests/strings/vararg.cpp +++ tests/strings/vararg.cpp @@ -213,6 +213,13 @@ void VarArgTestCase::ArgsValidation() wxString::Format("a string(%s,%s), ptr %p, int %i", wxString(), "foo", "char* as pointer", 1); +#if __cplusplus >= 201103 || wxCHECK_VISUALC_VERSION(10) + // Unfortunately we can't check the result as different standard libraries + // implementations format it in different ways, so just check that it + // compiles. + wxString::Format("null pointer is %p", nullptr); +#endif + // Microsoft has helpfully disabled support for "%n" in their CRT by // default starting from VC8 and somehow even calling // _set_printf_count_output() doesn't help here, so don't use "%n" at all