Skip to content

Commit

Permalink
Fix clang -Wunused-member-function warnings with FMT_MAYBE_UNUSED att…
Browse files Browse the repository at this point in the history
…ribute.

FMT_MAYBE_UNUSED currently expands to the [[maybe_unused]] attribute on C++17.

It could be extended to previous language versions with a compiler-specific attribute if required.
  • Loading branch information
refnum committed Mar 5, 2020
1 parent 153f753 commit aa902c3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@
# define FMT_NORETURN
#endif

#ifndef FMT_MAYBE_UNUSED
# if FMT_HAS_CPP_ATTRIBUTE(maybe_unused)
# define FMT_MAYBE_UNUSED [[maybe_unused]]
# else
# define FMT_MAYBE_UNUSED
# endif
#endif

#ifndef FMT_DEPRECATED
# if (FMT_HAS_CPP_ATTRIBUTE(deprecated) && __cplusplus >= 201402L) || \
FMT_MSC_VER >= 1900
Expand Down
3 changes: 3 additions & 0 deletions include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ FMT_FUNC int safe_strerror(int error_code, char*& buffer,
}

// Handle the result of GNU-specific version of strerror_r.
FMT_MAYBE_UNUSED
int handle(char* message) {
// If the buffer is full then the message is probably truncated.
if (message == buffer_ && strlen(buffer_) == buffer_size_ - 1)
Expand All @@ -95,11 +96,13 @@ FMT_FUNC int safe_strerror(int error_code, char*& buffer,
}

// Handle the case when strerror_r is not available.
FMT_MAYBE_UNUSED
int handle(internal::null<>) {
return fallback(strerror_s(buffer_, buffer_size_, error_code_));
}

// Fallback to strerror_s when strerror_r is not available.
FMT_MAYBE_UNUSED
int fallback(int result) {
// If the buffer is full then the message is probably truncated.
return result == 0 && strlen(buffer_) == buffer_size_ - 1 ? ERANGE
Expand Down
2 changes: 1 addition & 1 deletion include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -3549,7 +3549,7 @@ FMT_END_NAMESPACE
/* Use a macro-like name to avoid shadowing warnings. */ \
struct FMT_STRING : fmt::compile_string { \
using char_type = fmt::remove_cvref_t<decltype(*s)>; \
__VA_ARGS__ FMT_CONSTEXPR \
FMT_MAYBE_UNUSED __VA_ARGS__ FMT_CONSTEXPR \
operator fmt::basic_string_view<char_type>() const { \
/* FMT_STRING only accepts string literals. */ \
return fmt::internal::literal_to_view(s); \
Expand Down

0 comments on commit aa902c3

Please sign in to comment.