Skip to content

Commit

Permalink
Fix bogus "conditional expression is constant" MSVC warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Apr 5, 2015
1 parent aab64b5 commit fd53bb6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions format.h
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,10 @@ struct EnableIf {};
template<class T>
struct EnableIf<true, T> { typedef T type; };

// A helper function to suppress bogus "conditional expression is constant"
// warnings.
inline bool check(bool value) { return value; }

// Makes an Arg object from any type.
template <typename Char>
class MakeValue : public Arg {
Expand Down Expand Up @@ -859,7 +863,7 @@ class MakeValue : public Arg {
MakeValue(long value) {
// To minimize the number of types we need to deal with, long is
// translated either to int or to long long depending on its size.
if (sizeof(long) == sizeof(int))
if (check(sizeof(long) == sizeof(int)))
int_value = static_cast<int>(value);
else
long_long_value = value;
Expand All @@ -869,7 +873,7 @@ class MakeValue : public Arg {
}

MakeValue(unsigned long value) {
if (sizeof(unsigned long) == sizeof(unsigned))
if (check(sizeof(unsigned long) == sizeof(unsigned)))
uint_value = static_cast<unsigned>(value);
else
ulong_long_value = value;
Expand Down Expand Up @@ -2634,7 +2638,7 @@ struct ArgArraySize {
Arg array[fmt::internal::ArgArraySize<sizeof...(Args)>::VALUE] = { \
fmt::internal::MakeValue<Char>(args)... \
}; \
if (sizeof...(Args) > fmt::ArgList::MAX_PACKED_ARGS) \
if (fmt::internal::check((sizeof...(Args) > fmt::ArgList::MAX_PACKED_ARGS))) \
set_types(array, args...); \
call(FMT_FOR_EACH(FMT_GET_ARG_NAME, __VA_ARGS__), \
fmt::ArgList(fmt::internal::make_type(args...), array)); \
Expand Down

0 comments on commit fd53bb6

Please sign in to comment.