Jelajahi Sumber

config: avoid using pretty function with gcc < 9 (see #396)

Michele Caini 6 tahun lalu
induk
melakukan
f32f3ab895
2 mengubah file dengan 14 tambahan dan 5 penghapusan
  1. 4 0
      src/entt/config/config.h
  2. 10 5
      src/entt/core/type_info.hpp

+ 4 - 0
src/entt/config/config.h

@@ -56,6 +56,10 @@
 #ifndef ENTT_STANDARD_CPP
 #   if defined _MSC_VER
 #      define ENTT_PRETTY_FUNCTION __FUNCSIG__
+#      define ENTT_PRETTY_FUNCTION_CONSTEXPR ENTT_PRETTY_FUNCTION
+#   elif defined __clang__ || (defined __GNUC__ && __GNUC__ > 8)
+#      define ENTT_PRETTY_FUNCTION __PRETTY_FUNCTION__
+#      define ENTT_PRETTY_FUNCTION_CONSTEXPR ENTT_PRETTY_FUNCTION
 #   elif defined __GNUC__
 #      define ENTT_PRETTY_FUNCTION __PRETTY_FUNCTION__
 #   endif

+ 10 - 5
src/entt/core/type_info.hpp

@@ -7,10 +7,10 @@
 #include "hashed_string.hpp"
 
 
-#ifdef ENTT_PRETTY_FUNCTION
-#   define ENTT_TYPE_ID_API
-#else
+#ifndef ENTT_PRETTY_FUNCTION
 #   define ENTT_TYPE_ID_API ENTT_API
+#else
+#   define ENTT_TYPE_ID_API
 #endif
 
 
@@ -55,9 +55,14 @@ struct ENTT_TYPE_ID_API type_info {
      * @brief Returns the numeric representation of a given type.
      * @return The numeric representation of the given type.
      */
-#ifdef ENTT_PRETTY_FUNCTION
+#if defined ENTT_PRETTY_FUNCTION_CONSTEXPR
     static constexpr ENTT_ID_TYPE id() ENTT_NOEXCEPT {
-        constexpr auto value = entt::hashed_string::value(ENTT_PRETTY_FUNCTION);
+        constexpr auto value = entt::hashed_string::value(ENTT_PRETTY_FUNCTION_CONSTEXPR);
+        return value;
+    }
+#elif defined ENTT_PRETTY_FUNCTION
+    static ENTT_ID_TYPE id() ENTT_NOEXCEPT {
+        static const auto value = entt::hashed_string::value(ENTT_PRETTY_FUNCTION);
         return value;
     }
 #else