From fff49040ed57cf41dbf2b13769cbcabee6422c87 Mon Sep 17 00:00:00 2001 From: neargye Date: Thu, 18 Jun 2020 15:34:22 +0500 Subject: [PATCH] fix warnings --- example/example.cpp | 2 +- include/nameof.hpp | 58 ++++++++++++++++++++++++++------------------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index 30c7e52..c67c3a1 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -27,7 +27,7 @@ #include #include -struct Base { virtual void foo() {} }; +struct Base { virtual ~Base() = default; }; struct Derived : Base {}; diff --git a/include/nameof.hpp b/include/nameof.hpp index 0db9475..7b4e83b 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -49,9 +49,15 @@ #include #endif -#if defined(_MSC_VER) +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wsign-conversion" // Implicit conversion changes signedness: 'int' to 'size_t'. +#elif defined(__GNUC__) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wsign-conversion" // Implicit conversion changes signedness: 'int' to 'size_t'. +#elif defined(_MSC_VER) # pragma warning(push) -# pragma warning(disable : 26495) // Variable 'nameof::cstring::chars_' is uninitialized. +# pragma warning(disable : 26495) // Variable 'cstring::chars_' is uninitialized. #endif // Checks nameof_type compiler compatibility. @@ -658,31 +664,31 @@ template } // namespace nameof // Obtains simple (unqualified) string name of variable, function, macro. -#define NAMEOF(...) []() constexpr noexcept { \ - ::std::void_t(); \ - constexpr auto name = ::nameof::detail::pretty_name(#__VA_ARGS__, true); \ - static_assert(name.size() > 0, "Expression does not have a name."); \ - constexpr auto size = name.size(); \ - constexpr auto nameof = ::nameof::cstring{name}; \ - return nameof; }() +#define NAMEOF(...) []() constexpr noexcept { \ + ::std::void_t(); \ + constexpr auto __name = ::nameof::detail::pretty_name(#__VA_ARGS__, true); \ + static_assert(__name.size() > 0, "Expression does not have a name."); \ + constexpr auto __size = __name.size(); \ + constexpr auto __nameof = ::nameof::cstring<__size>{__name}; \ + return __nameof; }() // Obtains simple (unqualified) full (with template suffix) string name of variable, function, macro. -#define NAMEOF_FULL(...) []() constexpr noexcept { \ - ::std::void_t(); \ - constexpr auto name = ::nameof::detail::pretty_name(#__VA_ARGS__, false); \ - static_assert(name.size() > 0, "Expression does not have a name."); \ - constexpr auto size = name.size(); \ - constexpr auto nameof_full = ::nameof::cstring{name}; \ - return nameof_full; }() +#define NAMEOF_FULL(...) []() constexpr noexcept { \ + ::std::void_t(); \ + constexpr auto __name = ::nameof::detail::pretty_name(#__VA_ARGS__, false); \ + static_assert(__name.size() > 0, "Expression does not have a name."); \ + constexpr auto __size = __name.size(); \ + constexpr auto __nameof_full = ::nameof::cstring<__size>{__name}; \ + return __nameof_full; }() // Obtains raw string name of variable, function, macro. -#define NAMEOF_RAW(...) []() constexpr noexcept { \ - ::std::void_t(); \ - constexpr auto name = ::std::string_view{#__VA_ARGS__}; \ - static_assert(name.size() > 0, "Expression does not have a name."); \ - constexpr auto size = name.size(); \ - constexpr auto nameof_raw = ::nameof::cstring{name}; \ - return nameof_raw; }() +#define NAMEOF_RAW(...) []() constexpr noexcept { \ + ::std::void_t(); \ + constexpr auto __name = ::std::string_view{#__VA_ARGS__}; \ + static_assert(__name.size() > 0, "Expression does not have a name."); \ + constexpr auto __size = __name.size(); \ + constexpr auto __nameof_raw = ::nameof::cstring<__size>{__name}; \ + return __nameof_raw; }() // Obtains simple (unqualified) string enum name of enum variable. #define NAMEOF_ENUM(...) ::nameof::nameof_enum<::std::decay_t>(__VA_ARGS__) @@ -706,7 +712,11 @@ template // Obtains string name of type, using RTTI. #define NAMEOF_TYPE_RTTI(...) ::nameof::detail::demangle(typeid(__VA_ARGS__).name()) -#if defined(_MSC_VER) +#if defined(__clang__) +# pragma clang diagnostic pop +#elif defined(__GNUC__) +# pragma GCC diagnostic pop +#elif defined(_MSC_VER) # pragma warning(pop) #endif