From 2a118da028a6407b3c97f2f77f29e3a62eb76b59 Mon Sep 17 00:00:00 2001 From: Neargye Date: Sat, 1 Sep 2018 21:39:51 +0500 Subject: [PATCH] fix build --- include/nameof.hpp | 8 +++++++- test/test.cpp | 27 +++++++++++++++------------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/include/nameof.hpp b/include/nameof.hpp index 2389e04..81e66dd 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -435,12 +435,18 @@ constexpr cstring Nameof(const char* name, std::size_t size, bool with_suffix = template ::value && std::is_enum::value>::type> constexpr cstring NameofEnum(T value) { +#if defined(__clang__) || defined(_MSC_VER) return detail::NameofPretty(detail::NameofEnumImpl{}(value), false); +#elif defined(__GNUC__) + return detail::NameofEnumImpl{}(value); +#else +return {}; +#endif } template NAMEOF_TYPE_CONSTEXPR cstring NameofType() { - return true ? detail::NameofType>() : detail::NameofType>(); + return detail::NameofType>(); } template diff --git a/test/test.cpp b/test/test.cpp index 3e2b513..b059762 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -147,13 +147,12 @@ TEST_CASE("constexpr") { SECTION("NAMEOF_ENUM") { constexpr auto cx = NAMEOF_ENUM(color); -# if defined(__clang__) || defined(_MSC_VER) +#if defined(__clang__) || defined(_MSC_VER) static_assert(cx == "RED", ""); REQUIRE(cx == "RED"); -# elif defined(__GNUC__) - //static_assert(cx == "(Color)0", ""); - REQUIRE(cx == "(Color)0"); -# endif +#elif defined(__GNUC__) + REQUIRE(cx == "(const Color)0"); +#endif } #if defined(NAMEOF_TYPE_HAS_CONSTEXPR) @@ -315,10 +314,10 @@ TEST_CASE("NAMEOF_ENUM") { REQUIRE(NAMEOF_ENUM(directions) == "Right"); # elif defined(__GNUC__) REQUIRE(NAMEOF_ENUM(Color::RED) == "(Color)0"); - REQUIRE(NAMEOF_ENUM(color) == "0"); + REQUIRE(NAMEOF_ENUM(color) == "(const Color)0"); - REQUIRE(NAMEOF_ENUM(Directions::Right) == "2"); - REQUIRE(NAMEOF_ENUM(directions) == "2"); + REQUIRE(NAMEOF_ENUM(Directions::Right) == "(Directions)2"); + REQUIRE(NAMEOF_ENUM(directions) == "(const Directions)2"); # endif } @@ -428,9 +427,11 @@ TEST_CASE("Spaces and Tabs ignored") { REQUIRE(NAMEOF( struct_var ) == "struct_var"); REQUIRE(NAMEOF_FULL( struct_var ) == "struct_var"); REQUIRE(NAMEOF_RAW( struct_var ) == "struct_var"); - +#if defined(__clang__) || defined(_MSC_VER) REQUIRE(NAMEOF_ENUM( color ) == "RED"); - +#elif defined(__GNUC__) + REQUIRE(NAMEOF_ENUM( color ) == "(const Color)0"); +#endif REQUIRE(NAMEOF_TYPE( struct_var ) == "SomeStruct"); REQUIRE(NAMEOF_TYPE_T( decltype(struct_var) ) == "SomeStruct"); } @@ -439,9 +440,11 @@ TEST_CASE("Spaces and Tabs ignored") { REQUIRE(NAMEOF( struct_var ) == "struct_var"); REQUIRE(NAMEOF_FULL( struct_var ) == "struct_var"); REQUIRE(NAMEOF_RAW( struct_var ) == "struct_var"); - +#if defined(__clang__) || defined(_MSC_VER) REQUIRE(NAMEOF_ENUM( color ) == "RED"); - +#elif defined(__GNUC__) + REQUIRE(NAMEOF_ENUM( color ) == "(const Color)0"); +#endif REQUIRE(NAMEOF_TYPE( struct_var ) == "SomeStruct"); REQUIRE(NAMEOF_TYPE_T( decltype(struct_var) ) == "SomeStruct"); }