Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Add lifetime constraint to StringName -> String conversion.

Lukas Tenbrinka609c49df069
diff --git a/core/string/string_name.h b/core/string/string_name.h
index a85c17bf461..bf59b0d8043 100644
--- a/core/string/string_name.h
+++ b/core/string/string_name.h
@@ -125,12 +125,12 @@ public:
return (void *)_data;
}
- _FORCE_INLINE_ const String &string() const {
+ _FORCE_INLINE_ const String &string() const _LIFETIME_BOUND_ {
static const String EMPTY;
return _data ? _data->name : EMPTY;
}
- _FORCE_INLINE_ operator const String &() const {
+ _FORCE_INLINE_ operator const String &() const _LIFETIME_BOUND_ {
return string();
}
diff --git a/core/typedefs.h b/core/typedefs.h
index 91f5fda2ec5..3c60cd75071 100644
--- a/core/typedefs.h
+++ b/core/typedefs.h
@@ -62,6 +62,12 @@ static_assert(__cplusplus >= 201703L, "Minimum of C++17 required.");
#define GD_HAS_FEATURE(m_feature) 0
#endif
+#if defined(__has_cpp_attribute)
+#define GD_HAS_CPP_ATTRIBUTE(m_feature) __has_cpp_attribute(m_feature)
+#else
+#define GD_HAS_CPP_ATTRIBUTE(m_feature) 0
+#endif
+
#if (GD_HAS_FEATURE(address_sanitizer) || defined(__SANITIZE_ADDRESS__)) && !defined(ASAN_ENABLED)
#error Address sanitizer was enabled without defining `ASAN_ENABLED`
#endif
@@ -127,6 +133,18 @@ static_assert(__cplusplus >= 201703L, "Minimum of C++17 required.");
#define _ALLOW_DISCARD_ (void)
#endif
+#if GD_HAS_CPP_ATTRIBUTE(clang::lifetimebound)
+#define _LIFETIME_BOUND_ [[clang::lifetimebound]]
+#elif GD_HAS_CPP_ATTRIBUTE(gnu::lifetimebound)
+#define _LIFETIME_BOUND_ [[gnu::lifetimebound]]
+#elif GD_HAS_CPP_ATTRIBUTE(msvc::lifetimebound)
+#define _LIFETIME_BOUND_ [[msvc::lifetimebound]]
+#elif GD_HAS_CPP_ATTRIBUTE(lifetimebound)
+#define _LIFETIME_BOUND_ [[lifetimebound]]
+#else
+#define _LIFETIME_BOUND_
+#endif
+
// Make room for our constexpr's below by overriding potential system-specific macros.
#undef SIGN
#undef MIN