Skip to content

Commit 0373c40

Browse files
committed
fully compile time type deduction for GCC and clang
1 parent de3bef0 commit 0373c40

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

include/cpp2util.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,7 @@ auto assert_in_bounds(auto&& x, auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAU
593593
#ifdef CPP2_NO_RTTI
594594
// Compile-Time type name deduction for -fno-rtti builds
595595
//
596-
597-
auto process_type_name(std::string_view name) -> std::string_view {
596+
constexpr auto process_type_name(std::string_view name) -> std::string_view {
598597
#if defined(__clang__) || defined(__GNUC__)
599598
constexpr auto type_prefix = std::string_view("T = ");
600599
constexpr auto types_close_parenthesis = ']';
@@ -625,14 +624,15 @@ auto process_type_name(std::string_view name) -> std::string_view {
625624
}
626625

627626
template<typename T>
628-
auto type_name() -> std::string_view {
627+
constexpr auto type_name() -> std::string_view {
629628
#if defined(__clang__) || defined(__GNUC__)
630-
return process_type_name(__PRETTY_FUNCTION__);
629+
constexpr auto ret = process_type_name(__PRETTY_FUNCTION__);
631630
#elif defined(_MSC_VER)
632-
return process_type_name(__FUNCSIG__);
631+
constexpr auto ret = process_type_name(__FUNCSIG__);
633632
#else
634-
return "<cannot determine type>";
633+
constexpr auto ret = "<cannot determine type>";
635634
#endif
635+
return ret;
636636
}
637637

638638
#endif
@@ -654,7 +654,7 @@ auto type_name() -> std::string_view {
654654

655655
[[noreturn]] auto Throw(auto&& x, [[maybe_unused]] char const* msg) -> void {
656656
#ifdef CPP2_NO_EXCEPTIONS
657-
auto err = std::string{"Attempted to throw exception with type \""};
657+
auto err = std::string{"Attempted to throw (-fno-exception) type \""};
658658

659659
#ifdef CPP2_NO_RTTI
660660
err += type_name<decltype(x)>();

0 commit comments

Comments
 (0)