Skip to content

Commit

Permalink
Add a static assertion for issue Neargye#52
Browse files Browse the repository at this point in the history
  • Loading branch information
schaumb authored Mar 6, 2023
1 parent 84ce6d8 commit 3d98c9c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion include/nameof.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,13 @@ constexpr auto get_member_name() noexcept {
if constexpr (std::is_member_function_pointer_v<decltype(V)>) {
return n<V>();
} else {
return n<V, &(union_type_holder<decltype(get_base_type(V))>::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<V, &(union_type_holder<decltype(get_base_type(V))>::value.f.*V)>();
} else {
return "";
}
}
}

Expand Down

0 comments on commit 3d98c9c

Please # to comment.