From 1e67e10a9a9cd2b575791f891ab6f15b612b1e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= Date: Tue, 12 Feb 2019 20:09:06 +0100 Subject: [PATCH] Silence Warnings when using FMT_STRING() Clang 7 (or atleast QtCreator's Clang Code Model) says: Warning: unused member function 'operator basic_string_view' [-Wunused-member-function] And MinGW 8.1 says: Warning: typedef '::::str::char_type' locally defined but not used [-Wunused-local-typedefs] --- include/fmt/core.h | 16 ++++++++++++++++ include/fmt/format.h | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 50b79351..8f7daf1b 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -111,6 +111,22 @@ # define FMT_USE_NULLPTR 0 #endif +#ifndef FMT_MAYBE_UNUSED +# ifdef __has_cpp_attribute +# if __has_cpp_attribute(maybe_unused) +# define FMT_MAYBE_UNUSED [[maybe_unused]] +# endif +# else +# if (__cplusplus >= 201603L && FMT_GCC_VERSION >= 700) || \ + FMT_MSC_VER >= 1911 +# define FMT_MAYBE_UNUSED [[maybe_unused]] +# endif +# endif +#endif +#ifndef FMT_MAYBE_UNUSED +# define FMT_MAYBE_UNUSED +#endif + // Check if exceptions are disabled. #ifndef FMT_EXCEPTIONS # if (defined(__GNUC__) && !defined(__EXCEPTIONS)) || \ diff --git a/include/fmt/format.h b/include/fmt/format.h index 1bb24a52..012fd606 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3514,8 +3514,8 @@ FMT_END_NAMESPACE typedef typename std::remove_cv::type>::type>::type ct; \ struct str : fmt::compile_string { \ - typedef ct char_type; \ - FMT_CONSTEXPR operator fmt::basic_string_view() const { \ + FMT_MAYBE_UNUSED typedef ct char_type; \ + FMT_MAYBE_UNUSED FMT_CONSTEXPR operator fmt::basic_string_view() const { \ return {s, sizeof(s) / sizeof(ct) - 1}; \ } \ }; \