You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ad...@apache.org on 2021/08/02 12:34:30 UTC

[nifi-minifi-cpp] branch main updated: MINIFICPP-1425 Proceed to partial C++20 support

This is an automated email from the ASF dual-hosted git repository.

adebreceni pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git


The following commit(s) were added to refs/heads/main by this push:
     new 40c75e5  MINIFICPP-1425 Proceed to partial C++20 support
40c75e5 is described below

commit 40c75e5949e54248def95a092cc879c3d6203281
Author: Marton Szasz <sz...@apache.org>
AuthorDate: Mon Aug 2 14:32:43 2021 +0200

    MINIFICPP-1425 Proceed to partial C++20 support
    
    patch sol2 to not fail in C++20 mode
    on mac xcode/AppleClang, due to const char*/const char8_t*
    incompatibility and the fact that u8"string" literals are now
    const char8*.
    
    Signed-off-by: Adam Debreceni <ad...@apache.org>
    
    This closes #1142
---
 cmake/CppVersion.cmake         | 20 ++++++++++----------
 thirdparty/sol2-2.20.0/sol.hpp | 17 ++++++++++-------
 2 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/cmake/CppVersion.cmake b/cmake/CppVersion.cmake
index 3fbbe8e..59768c8 100644
--- a/cmake/CppVersion.cmake
+++ b/cmake/CppVersion.cmake
@@ -18,24 +18,24 @@
 function(set_cpp_version)
     if (MSVC)
         if ((MSVC_VERSION GREATER "1910") OR (MSVC_VERSION EQUAL "1910"))
-            add_compile_options("/std:c++17")
+            add_compile_options("/std:c++latest")
             add_compile_options("/permissive-")
         else()
             message(STATUS "The Visual Studio C++ compiler ${CMAKE_CXX_COMPILER} is not supported. Please use Visual Studio 2019 or newer.")
         endif()
-        set(CMAKE_CXX_STANDARD 17 PARENT_SCOPE)
+        set(CMAKE_CXX_STANDARD 20 PARENT_SCOPE)
     else()
         include(CheckCXXCompilerFlag)
-        CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
-        CHECK_CXX_COMPILER_FLAG("-std=c++1z" COMPILER_SUPPORTS_CXX1Z)
-        if(COMPILER_SUPPORTS_CXX17)
-            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17" PARENT_SCOPE)
-        elseif(COMPILER_SUPPORTS_CXX1Z)
-            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z" PARENT_SCOPE)
+        CHECK_CXX_COMPILER_FLAG("-std=c++20" COMPILER_SUPPORTS_CXX20)
+        CHECK_CXX_COMPILER_FLAG("-std=c++2a" COMPILER_SUPPORTS_CXX2A)
+        if(COMPILER_SUPPORTS_CXX20)
+            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20" PARENT_SCOPE)
+        elseif(COMPILER_SUPPORTS_CXX2A)
+            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++2a" PARENT_SCOPE)
         else()
-            message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no support for -std=c++17 or -std=c++1z. Please use a more recent C++ compiler version.")
+            message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no support for -std=c++20 or -std=c++2a. Please use a more recent C++ compiler version.")
         endif()
-        set(CMAKE_CXX_STANDARD 17 PARENT_SCOPE)
+        set(CMAKE_CXX_STANDARD 20 PARENT_SCOPE)
     endif()
 
     set(CMAKE_CXX_STANDARD_REQUIRED ON PARENT_SCOPE)
diff --git a/thirdparty/sol2-2.20.0/sol.hpp b/thirdparty/sol2-2.20.0/sol.hpp
index 9a2858f..e0c5464 100644
--- a/thirdparty/sol2-2.20.0/sol.hpp
+++ b/thirdparty/sol2-2.20.0/sol.hpp
@@ -1719,7 +1719,8 @@ namespace sol {
 #else
 			is_specialization_of<meta::unqualified_t<T>, basic_string_view>,
 #endif
-			meta::all<std::is_array<unqualified_t<T>>, meta::any_same<meta::unqualified_t<std::remove_all_extents_t<meta::unqualified_t<T>>>, char, char16_t, char32_t, wchar_t>>
+			// Added char8_t to the list. Patched by szaszm in minifi-cpp to avoid compilation error on C++20, where char8_t is incompatible with char.
+			meta::all<std::is_array<unqualified_t<T>>, meta::any_same<meta::unqualified_t<std::remove_all_extents_t<meta::unqualified_t<T>>>, char, char8_t, char16_t, char32_t, wchar_t>>
 		>;
 
 		template <typename T>
@@ -5350,7 +5351,8 @@ namespace sol {
 		template <typename T>
 		struct is_container<T, std::enable_if_t<meta::all<
 			std::is_array<meta::unqualified_t<T>>
-			, meta::neg<meta::any_same<std::remove_all_extents_t<meta::unqualified_t<T>>, char, wchar_t, char16_t, char32_t>>
+			// Added char8_t to the list. Patched by szaszm in minifi-cpp to avoid compilation error on C++20, where char8_t is incompatible with char.
+			, meta::neg<meta::any_same<std::remove_all_extents_t<meta::unqualified_t<T>>, char, wchar_t, char8_t, char16_t, char32_t>>
 			>::value
 		>> : std::true_type {};
 
@@ -7862,14 +7864,15 @@ namespace sol {
 			return key;
 		}
 
-		inline decltype(auto) base_class_index_propogation_key() {
+		// Casting types to const char* (from const char8_t*). Patched by szaszm in minifi-cpp to avoid compilation error on C++20, where char8_t is incompatible with char.
+		inline const char* const& base_class_index_propogation_key() {
 			static const auto& key = u8"\xF0\x9F\x8C\xB2.index";
-			return key;
+			return reinterpret_cast<const char* const&>(key);
 		}
 
-		inline decltype(auto) base_class_new_index_propogation_key() {
+		inline const char* const& base_class_new_index_propogation_key() {
 			static const auto& key = u8"\xF0\x9F\x8C\xB2.new_index";
-			return key;
+			return reinterpret_cast<const char* const&>(key);
 		}
 
 		template <typename T, typename... Bases>
@@ -18105,7 +18108,7 @@ namespace sol {
 				return;
 			const char* metakey = &usertype_traits<Base>::metatable()[0];
 			const char* gcmetakey = &usertype_traits<Base>::gc_table()[0];
-			const char* basewalkkey = is_index ? static_cast<const char*>(detail::base_class_index_propogation_key()) : static_cast<const char*>(detail::base_class_new_index_propogation_key());
+			const char* basewalkkey = is_index ? detail::base_class_index_propogation_key() : detail::base_class_new_index_propogation_key();
 
 			luaL_getmetatable(L, metakey);
 			if (type_of(L, -1) == type::lua_nil) {