diff --git a/.travis.yml b/.travis.yml index ceed310..fc5e261 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,17 @@ matrix: env: - CXX_COMPILER=g++-8 CC_COMPILER=gcc-8 + - os: linux + compiler: g++ + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-9 + env: + - CXX_COMPILER=g++-9 CC_COMPILER=gcc-9 + - os: linux compiler: clang++ addons: diff --git a/include/nameof.hpp b/include/nameof.hpp index 20be299..fc2890a 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -168,8 +168,10 @@ template #elif defined(__GNUC__) std::string_view name{__PRETTY_FUNCTION__}; constexpr auto prefix = sizeof("constexpr std::string_view nameof::detail::nameof_enum_impl() [with E = ") + nameof_type_impl>().length() + sizeof("; V = "); +# if __GNUC__ < 9 constexpr auto suffix = sizeof("; std::string_view = std::basic_string_view]") - 1; name.remove_prefix(prefix); +# endif #elif defined(_MSC_VER) std::string_view name{__FUNCSIG__}; constexpr auto suffix = sizeof(">(void) noexcept") - 1; @@ -179,7 +181,7 @@ template #if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER) name.remove_suffix(suffix); -# if defined(__clang__) || defined(_MSC_VER) +# if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 9) || defined(_MSC_VER) for (std::size_t i = name.size(); i > 0; --i) { if (!is_name_char(name[i - 1])) { name.remove_prefix(i); diff --git a/test/test.cpp b/test/test.cpp index c0c7bea..0d89a9d 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -212,7 +212,7 @@ TEST_CASE("NAMEOF_RAW") { TEST_CASE("NAMEOF_ENUM") { Color color_ = Color::BLUE; Color m[3] = {Color::RED, Color::GREEN, Color::BLUE}; -#if defined(__clang__) || defined(_MSC_VER) +#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 9) || defined(_MSC_VER) REQUIRE(NAMEOF_ENUM(Color::RED) == "RED"); REQUIRE(NAMEOF_ENUM(color) == "RED"); @@ -240,7 +240,7 @@ TEST_CASE("NAMEOF_ENUM") { TEST_CASE("nameof::nameof_enum(value)") { Color color_ = Color::BLUE; Color m[3] = {Color::RED, Color::GREEN, Color::BLUE}; -#if defined(__clang__) || defined(_MSC_VER) +#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 9) || defined(_MSC_VER) REQUIRE(nameof::nameof_enum(Color::RED) == "RED"); REQUIRE(nameof::nameof_enum(color) == "RED"); @@ -268,7 +268,7 @@ TEST_CASE("nameof::nameof_enum(value)") { TEST_CASE("nameof::nameof_enum()") { constexpr Color color_ = Color::BLUE; constexpr Color m[3] = {Color::RED, Color::GREEN, Color::BLUE}; -#if defined(__clang__) || defined(_MSC_VER) +#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 9) || defined(_MSC_VER) REQUIRE(nameof::nameof_enum() == "RED"); REQUIRE(nameof::nameof_enum() == "RED");