From 55efc9e60742d0de61e39556084d09f2332b99be Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 31 Jan 2020 17:13:06 +0100 Subject: [PATCH] Allow using wxStrtox() functions with nullptr with MSVS too Add a unit test checking that it compiles (and works). This extends the changes of 63b1f00eb87fd366209ca7e09300fd1e309eb7ee to cover MSVS as well. --- include/wx/wxcrt.h | 2 +- tests/strings/crt.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/include/wx/wxcrt.h b/include/wx/wxcrt.h index cfdc47257e..e8bdc628c2 100644 --- a/include/wx/wxcrt.h +++ b/include/wx/wxcrt.h @@ -844,7 +844,7 @@ template<> struct wxStrtoxCharType return NULL; } }; -#if __cplusplus >= 201103 +#ifdef wxHAS_NULLPTR_T template<> struct wxStrtoxCharType { typedef const char* Type; diff --git a/tests/strings/crt.cpp b/tests/strings/crt.cpp index 54bce32458..6d728f3cb8 100644 --- a/tests/strings/crt.cpp +++ b/tests/strings/crt.cpp @@ -233,3 +233,33 @@ TEST_CASE("CRT::Strnlen", "[crt][strnlen]") CHECK( wxStrnlen("1234" "\0" "78", 12) == 4 ); CHECK( wxStrnlen(L"1234" L"\0" L"5678", 12) == 4 ); } + +TEST_CASE("CRT::Strtod", "[crt][strtod]") +{ + const wxString s = "123@"; + const double d = 123.0; + + SECTION("char") + { + char* end = NULL; + CHECK( wxStrtod(s, &end) == d ); + REQUIRE( end ); + CHECK( *end == '@' ); + } + + SECTION("wchar_t") + { + wchar_t* end = NULL; + CHECK( wxStrtod(s, &end) == d ); + REQUIRE( end ); + CHECK( *end == L'@' ); + } + + SECTION("other") + { + CHECK( wxStrtod(s, 0) == d ); +#ifdef wxHAS_NULLPTR_T + CHECK( wxStrtod(s, nullptr) == d ); +#endif + } +}