From 9494cbd4aadef3c34f7dccdc93d544b00c0a26b9 Mon Sep 17 00:00:00 2001 From: Bela Schaum Date: Mon, 6 Mar 2023 13:02:46 +0000 Subject: [PATCH] Add a static assertion for issue https://github.com/Neargye/nameof/issues/52 (#57) --- include/nameof.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/nameof.hpp b/include/nameof.hpp index 44230cc..f22cfdd 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -988,7 +988,13 @@ constexpr auto get_member_name() noexcept { if constexpr (std::is_member_function_pointer_v) { return n(); } else { - return n::value.f.*V)>(); + constexpr bool is_defined = sizeof(decltype(get_base_type(V))) != 0; + static_assert(is_defined, "Member name can use only if the struct is already fully defined. Please use NAMEOF macro, or separate definition and declaration."); + if constexpr (is_defined) { + return n::value.f.*V)>(); + } else { + return ""; + } } }