From fd53bb6fb88a23e38ec4fe331bfe95d7372d49c9 Mon Sep 17 00:00:00 2001 From: vitaut Date: Sun, 5 Apr 2015 11:27:07 -0700 Subject: [PATCH] Fix bogus "conditional expression is constant" MSVC warnings --- format.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/format.h b/format.h index 3a82f827..8d54bf52 100644 --- a/format.h +++ b/format.h @@ -800,6 +800,10 @@ struct EnableIf {}; template struct EnableIf { 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 class MakeValue : public Arg { @@ -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(value); else long_long_value = value; @@ -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(value); else ulong_long_value = value; @@ -2634,7 +2638,7 @@ struct ArgArraySize { Arg array[fmt::internal::ArgArraySize::VALUE] = { \ fmt::internal::MakeValue(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)); \