diff --git a/build/cmake/functions.cmake b/build/cmake/functions.cmake index 1c74202845..26268d4db0 100644 --- a/build/cmake/functions.cmake +++ b/build/cmake/functions.cmake @@ -77,20 +77,12 @@ endmacro() function(wx_set_common_target_properties target_name) cmake_parse_arguments(wxCOMMON_TARGET_PROPS "DEFAULT_WARNINGS" "" "" ${ARGN}) - if(DEFINED wxBUILD_CXX_STANDARD AND NOT wxBUILD_CXX_STANDARD STREQUAL COMPILER_DEFAULT) - # TODO: implement for older CMake versions ? - set_target_properties(${target_name} PROPERTIES CXX_STANDARD ${wxBUILD_CXX_STANDARD}) - if( - APPLE AND - CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 10.9 AND - (wxBUILD_CXX_STANDARD EQUAL 11 OR wxBUILD_CXX_STANDARD EQUAL 14) - ) - if(CMAKE_GENERATOR STREQUAL "Xcode") - set_target_properties(${target_name} PROPERTIES XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY libc++) - else() - target_compile_options(${target_name} PUBLIC "-stdlib=libc++") - target_link_libraries(${target_name} PRIVATE "-stdlib=libc++") - endif() + if(APPLE AND CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 10.9 AND wxHAS_CXX11) + if(CMAKE_GENERATOR STREQUAL "Xcode") + set_target_properties(${target_name} PROPERTIES XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY libc++) + else() + target_compile_options(${target_name} PUBLIC "-stdlib=libc++") + target_link_libraries(${target_name} PRIVATE "-stdlib=libc++") endif() endif() set_target_properties(${target_name} PROPERTIES diff --git a/build/cmake/init.cmake b/build/cmake/init.cmake index 32513f1241..6709c371b8 100644 --- a/build/cmake/init.cmake +++ b/build/cmake/init.cmake @@ -8,6 +8,15 @@ # Licence: wxWindows licence ############################################################################# +if(DEFINED wxBUILD_CXX_STANDARD AND NOT wxBUILD_CXX_STANDARD STREQUAL COMPILER_DEFAULT) + set(CMAKE_CXX_STANDARD ${wxBUILD_CXX_STANDARD}) +endif() +if(NOT CMAKE_CXX_STANDARD EQUAL 98) + set(wxHAS_CXX11 TRUE) +else() + set(wxHAS_CXX11 FALSE) +endif() + if(MSVC) # Determine MSVC runtime library flag set(MSVC_LIB_USE "/MD") diff --git a/build/cmake/options.cmake b/build/cmake/options.cmake index 5417d4a136..bb5a205015 100644 --- a/build/cmake/options.cmake +++ b/build/cmake/options.cmake @@ -36,15 +36,17 @@ endif() if(MSVC) wx_option(wxBUILD_MSVC_MULTIPROC "Enable multi-processor compilation for MSVC") -else() - # Other compilers support setting the C++ standard, present it an option to the user +endif() + +if(NOT MSVC OR MSVC_VERSION GREATER 1800) + # support setting the C++ standard, present it an option to the user if(DEFINED CMAKE_CXX_STANDARD) set(wxCXX_STANDARD_DEFAULT ${CMAKE_CXX_STANDARD}) else() set(wxCXX_STANDARD_DEFAULT COMPILER_DEFAULT) endif() wx_option(wxBUILD_CXX_STANDARD "C++ standard used to build wxWidgets targets" - ${wxCXX_STANDARD_DEFAULT} STRINGS COMPILER_DEFAULT 98 11 14 17) + ${wxCXX_STANDARD_DEFAULT} STRINGS COMPILER_DEFAULT 98 11 14 17 20) endif() if(WIN32) diff --git a/build/cmake/samples/CMakeLists.txt b/build/cmake/samples/CMakeLists.txt index bb0df2e8d5..7b3a9dead2 100644 --- a/build/cmake/samples/CMakeLists.txt +++ b/build/cmake/samples/CMakeLists.txt @@ -213,7 +213,7 @@ wx_list_add_prefix(WIDGETS_RC_FILES icons/ stattext.xpm text.xpm timepick.xpm toggle.xpm ) wx_add_sample(widgets IMPORTANT ${SAMPLE_WIDGETS_SRC} - DATA ${WIDGETS_RC_FILES} textctrl.cpp + DATA ${WIDGETS_RC_FILES} textctrl.cpp ../image/toucan.png ) wx_add_sample(wizard DEPENDS wxUSE_WIZARDDLG) wx_add_sample(wrapsizer) diff --git a/build/cmake/setup.cmake b/build/cmake/setup.cmake index 35ba62b64b..deb456924b 100644 --- a/build/cmake/setup.cmake +++ b/build/cmake/setup.cmake @@ -23,11 +23,7 @@ include(CheckTypeSize) include(CMakePushCheckState) include(TestBigEndian) -if( - APPLE AND - CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 10.9 AND - (CMAKE_CXX_STANDARD EQUAL 11 OR CMAKE_CXX_STANDARD EQUAL 14) - ) +if(APPLE AND CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 10.9 AND wxHAS_CXX11) set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} "-stdlib=libc++") endif() @@ -147,7 +143,7 @@ wx_check_c_source_compiles( stdio.h ) #TODO: wxNO_VARIADIC_MACROS -if(wxUSE_STL) +if(wxUSE_STL AND NOT wxHAS_CXX11) wx_check_cxx_source_compiles(" std::vector moo; std::list foo; @@ -172,6 +168,12 @@ if(wxUSE_STL) HAVE_STD_STRING_COMPARE string ) + + wx_check_cxx_source_compiles( + "std::wstring s;" + HAVE_STD_WSTRING + string + ) endif() # Check for availability of GCC's atomic operations builtins. @@ -588,13 +590,6 @@ check_include_file(w32api.h HAVE_W32API_H) check_include_file(wchar.h HAVE_WCHAR_H) check_include_file(wcstr.h HAVE_WCSTR_H) - -wx_check_cxx_source_compiles( - "std::wstring s;" - HAVE_STD_WSTRING - string - ) - if(wxUSE_DATETIME) # check for timezone variable # doesn't exist under Darwin / Mac OS X which uses tm_gmtoff instead diff --git a/docs/doxygen/mainpages/const_cpp.h b/docs/doxygen/mainpages/const_cpp.h index 2a23d7381e..75ffbad426 100644 --- a/docs/doxygen/mainpages/const_cpp.h +++ b/docs/doxygen/mainpages/const_cpp.h @@ -171,6 +171,9 @@ Currently the following symbols exist: wxBitmapToggleButton class is available in addition to wxToggleButton.} @itemdef{wxHAS_CONFIG_TEMPLATE_RW, Defined if the currently used compiler supports template Read() and Write() methods in wxConfig.} +@itemdef{wxHAS_MEMBER_DEFAULT, Defined if the currently used compiler supports + C++11 @c =default. @c wxMEMBER_DEFAULT is defined as this keyword in this + case, and as nothing otherwise.} @itemdef{wxHAS_LARGE_FILES, Defined if wxFile supports files more than 4GB in size (notice that you must include @c wx/filefn.h before testing for this symbol).} diff --git a/include/wx/animate.h b/include/wx/animate.h index e643131577..f2db61fc12 100644 --- a/include/wx/animate.h +++ b/include/wx/animate.h @@ -38,9 +38,9 @@ public: wxAnimation(); explicit wxAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY); -#if __cplusplus >= 201103 - wxAnimation(const wxAnimation&) = default; - wxAnimation& operator=(const wxAnimation&) = default; +#ifdef wxHAS_MEMBER_DEFAULT + wxAnimation(const wxAnimation&) wxMEMBER_DEFAULT; + wxAnimation& operator=(const wxAnimation&) wxMEMBER_DEFAULT; #endif bool IsOk() const; diff --git a/include/wx/defs.h b/include/wx/defs.h index a7472b60b3..98d06650ba 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -285,6 +285,14 @@ typedef short int WXTYPE; #define wxOVERRIDE #endif /* HAVE_OVERRIDE */ +/* same for defaulted member function keyword */ +#if __cplusplus >= 201103L || wxCHECK_VISUALC_VERSION(14) + #define wxHAS_MEMBER_DEFAULT + #define wxMEMBER_DEFAULT = default +#else + #define wxMEMBER_DEFAULT +#endif + /* Support for nullptr is available since MSVS 2010, even though it doesn't define __cplusplus as a C++11 compiler. @@ -2994,7 +3002,7 @@ typedef const void* WXWidget; /* macros to define a class without copy ctor nor assignment operator */ /* --------------------------------------------------------------------------- */ -#if defined(__cplusplus) && __cplusplus >= 201103L +#if defined(__cplusplus) && (__cplusplus >= 201103L || wxCHECK_VISUALC_VERSION(14)) #define wxMEMBER_DELETE = delete #else #define wxMEMBER_DELETE diff --git a/include/wx/msw/rt/utils.h b/include/wx/msw/rt/utils.h index b315531090..213dfe41b7 100644 --- a/include/wx/msw/rt/utils.h +++ b/include/wx/msw/rt/utils.h @@ -66,11 +66,9 @@ public: operator HSTRING() const { return m_hstring; }; - static const TempStringRef Make(const wxString &str); + TempStringRef(const wxString& str); private: - TempStringRef(const wxString &str); - HSTRING m_hstring; HSTRING_HEADER m_header; diff --git a/include/wx/unichar.h b/include/wx/unichar.h index 55d4006803..a7cb03079c 100644 --- a/include/wx/unichar.h +++ b/include/wx/unichar.h @@ -267,8 +267,8 @@ public: wxUniCharRef& operator=(const wxUniCharRef& c) { if (&c != this) *this = c.UniChar(); return *this; } -#if __cplusplus >= 201103 - wxUniCharRef(const wxUniCharRef&) = default; +#ifdef wxHAS_MEMBER_DEFAULT + wxUniCharRef(const wxUniCharRef&) wxMEMBER_DEFAULT; #endif #define wxUNICHAR_REF_DEFINE_OPERATOR_EQUAL(type) \ diff --git a/samples/regtest/regtest.cpp b/samples/regtest/regtest.cpp index 2004e34ce9..2a91c2583b 100644 --- a/samples/regtest/regtest.cpp +++ b/samples/regtest/regtest.cpp @@ -1070,9 +1070,9 @@ bool RegTreeCtrl::TreeNode::OnExpand() case wxRegKey::Type_Dword: { - long l; - m_pKey->QueryValue(str, &l); - strItem << l; + long ldw; + m_pKey->QueryValue(str, &ldw); + strItem << ldw; } wxFALLTHROUGH; diff --git a/src/common/arrstr.cpp b/src/common/arrstr.cpp index e3ebe2e43e..1b05c1d556 100644 --- a/src/common/arrstr.cpp +++ b/src/common/arrstr.cpp @@ -59,7 +59,7 @@ wxArrayString::wxArrayString(size_t sz, const wxString* a) #include "wx/arrstr.h" -#if __cplusplus >= 201103L +#if __cplusplus >= 201103L || wxCHECK_VISUALC_VERSION(14) int wxArrayString::Index(const wxString& str, bool bCase, bool WXUNUSED(bFromEnd)) const { @@ -153,7 +153,7 @@ wxStringCompareLess wxStringCompare(F f) void wxArrayString::Sort(CompareFunction function) { std::sort(begin(), end(), -#if __cplusplus >= 201103L +#if __cplusplus >= 201103L || wxCHECK_VISUALC_VERSION(14) [function](const wxString& s1, const wxString& s2) { return function(s1, s2) < 0; @@ -185,7 +185,7 @@ int wxSortedArrayString::Index(const wxString& str, wxSortedArrayString::const_iterator it = std::lower_bound(begin(), end(), str, -#if __cplusplus >= 201103L +#if __cplusplus >= 201103L || wxCHECK_VISUALC_VERSION(14) [](const wxString& s1, const wxString& s2) { return s1 < s2; diff --git a/src/msw/rt/notifmsgrt.cpp b/src/msw/rt/notifmsgrt.cpp index 1f7e7fd1a3..3b9ba571ce 100644 --- a/src/msw/rt/notifmsgrt.cpp +++ b/src/msw/rt/notifmsgrt.cpp @@ -64,7 +64,7 @@ public: m_impl = NULL; } - // DesktopToastActivatedEventHandler + // DesktopToastActivatedEventHandler IFACEMETHODIMP Invoke(IToastNotification *sender, IInspectable* args); // DesktopToastDismissedEventHandler @@ -170,7 +170,7 @@ public: HRESULT CreateToast(IXmlDocument *xml) { - HRESULT hr = ms_toastMgr->CreateToastNotifierWithId(rt::TempStringRef::Make(ms_appId), &m_notifier); + HRESULT hr = ms_toastMgr->CreateToastNotifierWithId(rt::TempStringRef(ms_appId), &m_notifier); if ( SUCCEEDED(hr) ) { wxCOMPtr factory; @@ -215,7 +215,7 @@ public: if ( SUCCEEDED(hr) ) { wxCOMPtr nodeList; - hr = (*toastXml)->GetElementsByTagName(rt::TempStringRef::Make("text"), &nodeList); + hr = (*toastXml)->GetElementsByTagName(rt::TempStringRef("text"), &nodeList); if ( SUCCEEDED(hr) ) { hr = SetNodeListValueString(0, m_title, nodeList, *toastXml); @@ -244,7 +244,7 @@ public: { wxCOMPtr inputText; - HRESULT hr = xml->CreateTextNode(rt::TempStringRef::Make(str), &inputText); + HRESULT hr = xml->CreateTextNode(rt::TempStringRef(str), &inputText); if ( SUCCEEDED(hr) ) { wxCOMPtr inputTextNode; diff --git a/src/msw/rt/utilsrt.cpp b/src/msw/rt/utilsrt.cpp index c21c7fe55a..ec2fb3491e 100644 --- a/src/msw/rt/utilsrt.cpp +++ b/src/msw/rt/utilsrt.cpp @@ -166,15 +166,14 @@ int RTCore::ms_isAvailable = -1; // wxWinRT::TempStringRef // -const TempStringRef TempStringRef::Make(const wxString &str) -{ - return TempStringRef(str); -} - TempStringRef::TempStringRef(const wxString &str) + : m_hstring(NULL), m_header() { if ( !RTCore::IsAvailable() ) + { wxLogDebug("Can not create string reference without WinRT"); + return; + } // This creates a fast-pass string which must not be deleted using WindowsDeleteString HRESULT hr = RTCore::Get().WindowsCreateStringReference( @@ -221,7 +220,7 @@ bool GetActivationFactory(const wxString& activatableClassId, REFIID iid, void * if ( !RTCore::IsAvailable() ) return false; - HRESULT hr = RTCore::Get().RoGetActivationFactory(TempStringRef::Make(activatableClassId), iid, factory); + HRESULT hr = RTCore::Get().RoGetActivationFactory(TempStringRef(activatableClassId), iid, factory); if ( FAILED(hr) ) { wxLogDebug("RoGetActivationFactory failed %.8x", hr); diff --git a/tests/test.cpp b/tests/test.cpp index bb4b04564f..851785a72c 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -135,7 +135,11 @@ static void TestAssertHandler(const wxString& file, // so we'd just die without any useful information -- abort instead. abortReason << assertMessage << "in a worker thread."; } +#if __cplusplus >= 201703L || wxCHECK_VISUALC_VERSION(14) + else if ( uncaught_exceptions() ) +#else else if ( uncaught_exception() ) +#endif { // Throwing while already handling an exception would result in // terminate() being called and we wouldn't get any useful information