diff --git a/.travis.yml b/.travis.yml index 6ef03aa7..3d01de23 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,13 +23,10 @@ env: o1F2EwFbiso0EmtzhAPs19ujiVxkLn4= matrix: - exclude: - - env: TRAVIS_EMPTY_JOB_WORKAROUND=true include: # Documentation - - env: CXX_COMPILER=g++-6 BUILD=Doc + - env: BUILD=Doc sudo: required - compiler: gcc # g++ 6 on Linux with C++14 - env: CXX_COMPILER=g++-6 BUILD=Debug STANDARD=14 compiler: gcc @@ -116,15 +113,9 @@ matrix: - env: CXX_COMPILER=g++-4.4 BUILD=Debug STANDARD=0x compiler: gcc -install: - - DEPS_DIR="${TRAVIS_BUILD_DIR}/deps" - - mkdir -p ${DEPS_DIR} && cd ${DEPS_DIR} - - - cd ${TRAVIS_BUILD_DIR} - before_script: - if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then export CXX=${CXX_COMPILER}; fi - - ${CXX} --version + - if [[ "${BUILD}" != "Doc" ]]; then ${CXX} --version; fi script: - support/travis-build.py diff --git a/include/fmt/core.h b/include/fmt/core.h index 17b685a2..e8a6f615 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -36,6 +36,12 @@ # define FMT_HAS_CPP_ATTRIBUTE(x) 0 #endif +#if defined(__GNUC__) && !defined(__clang__) +# define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) +#else +# define FMT_GCC_VERSION 0 +#endif + #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) # define FMT_HAS_GXX_CXX11 FMT_GCC_VERSION #else @@ -557,21 +563,22 @@ struct typed_value : value { template FMT_CONSTEXPR basic_format_arg make_arg(const T &value); -#if FMT_GCC_VERSION >= 406 -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wuseless-cast" -#endif - #define FMT_MAKE_VALUE(TAG, ArgType, ValueType) \ template \ FMT_CONSTEXPR typed_value make_value(ArgType val) { \ return static_cast(val); \ } +#define FMT_MAKE_VALUE_SAME(TAG, Type) \ + template \ + FMT_CONSTEXPR typed_value make_value(Type val) { \ + return val; \ + } + FMT_MAKE_VALUE(bool_type, bool, int) FMT_MAKE_VALUE(int_type, short, int) FMT_MAKE_VALUE(uint_type, unsigned short, unsigned) -FMT_MAKE_VALUE(int_type, int, int) +FMT_MAKE_VALUE_SAME(int_type, int) FMT_MAKE_VALUE(uint_type, unsigned, unsigned) // To minimize the number of types we need to deal with, long is translated @@ -586,7 +593,7 @@ FMT_MAKE_VALUE( (sizeof(unsigned long) == sizeof(unsigned) ? uint_type : ulong_long_type), unsigned long, ulong_type) -FMT_MAKE_VALUE(long_long_type, long long, long long) +FMT_MAKE_VALUE_SAME(long_long_type, long long) FMT_MAKE_VALUE(ulong_long_type, unsigned long long, unsigned long long) FMT_MAKE_VALUE(int_type, signed char, int) FMT_MAKE_VALUE(uint_type, unsigned char, unsigned) @@ -601,8 +608,8 @@ inline typed_value make_value(wchar_t val) { #endif FMT_MAKE_VALUE(double_type, float, double) -FMT_MAKE_VALUE(double_type, double, double) -FMT_MAKE_VALUE(long_double_type, long double, long double) +FMT_MAKE_VALUE_SAME(double_type, double) +FMT_MAKE_VALUE_SAME(long_double_type, long double) // Formatting of wide strings into a narrow buffer and multibyte strings // into a wide buffer is disallowed (https://github.com/fmtlib/fmt/pull/606). @@ -612,28 +619,22 @@ FMT_MAKE_VALUE(cstring_type, const typename C::char_type*, const typename C::char_type*) FMT_MAKE_VALUE(cstring_type, signed char*, const signed char*) -FMT_MAKE_VALUE(cstring_type, const signed char*, const signed char*) +FMT_MAKE_VALUE_SAME(cstring_type, const signed char*) FMT_MAKE_VALUE(cstring_type, unsigned char*, const unsigned char*) -FMT_MAKE_VALUE(cstring_type, const unsigned char*, const unsigned char*) -FMT_MAKE_VALUE(string_type, basic_string_view, - basic_string_view) +FMT_MAKE_VALUE_SAME(cstring_type, const unsigned char*) +FMT_MAKE_VALUE_SAME(string_type, basic_string_view) FMT_MAKE_VALUE(string_type, typename basic_string_view::type, basic_string_view) FMT_MAKE_VALUE(string_type, const std::basic_string&, basic_string_view) FMT_MAKE_VALUE(pointer_type, void*, const void*) -FMT_MAKE_VALUE(pointer_type, const void*, const void*) +FMT_MAKE_VALUE_SAME(pointer_type, const void*) #if FMT_USE_NULLPTR FMT_MAKE_VALUE(pointer_type, std::nullptr_t, const void*) #endif -#if FMT_GCC_VERSION >= 406 -// -Wuseless-cast -# pragma GCC diagnostic pop -#endif - // Formatting of arbitrary pointers is disallowed. If you want to output a // pointer cast it to "void *" or "const void *". In particular, this forbids // formatting of "[const] volatile char *" which is printed as bool by diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index ac29038c..2495b0f3 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -65,8 +65,7 @@ inline fmt::internal::null<> strerror_s(char *, std::size_t, ...) { FMT_BEGIN_NAMESPACE -FMT_FUNC format_error::~format_error() throw() {} -FMT_FUNC system_error::~system_error() FMT_DTOR_NOEXCEPT {} +namespace { #ifndef _MSC_VER # define FMT_SNPRINTF snprintf diff --git a/include/fmt/format.h b/include/fmt/format.h index f7bfe233..75ca3a17 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -37,12 +37,6 @@ #include #include -#if defined(__GNUC__) && !defined(__clang__) -# define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) -#else -# define FMT_GCC_VERSION 0 -#endif - #ifdef __clang__ # define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__) #else @@ -63,7 +57,8 @@ # define FMT_MSC_VER 0 #endif -#if FMT_GCC_VERSION >= 406 || FMT_CLANG_VERSION +#if (defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 406) || \ + FMT_CLANG_VERSION # pragma GCC diagnostic push // Disable the warning about declaration shadowing because it affects too @@ -81,8 +76,6 @@ # pragma clang diagnostic ignored "-Wweak-vtables" # pragma clang diagnostic ignored "-Wpadded" # pragma clang diagnostic ignored "-Wgnu-statement-expression" -# pragma clang diagnostic ignored "-Wc++98-compat" -# pragma clang diagnostic ignored "-Wc++98-compat-pedantic" # pragma clang diagnostic ignored "-Wglobal-constructors" # pragma clang diagnostic ignored "-Wdisabled-macro-expansion" # pragma clang diagnostic ignored "-Wdocumentation-unknown-command" @@ -3146,7 +3139,7 @@ struct formatter< break; case internal::char_type: handle_char_specs(specs_, internal::char_specs_checker( - type_spec, eh)); + static_cast(type_spec), eh)); break; case internal::double_type: case internal::long_double_type: @@ -3178,8 +3171,8 @@ struct formatter< internal::handle_dynamic_spec( specs_.precision_, specs_.precision_ref, ctx); typedef output_range range; - visit(arg_formatter(ctx, specs_), + typename FormatContext::char_type> range_type; + visit(arg_formatter(ctx, specs_), internal::make_arg(val)); return ctx.out(); } diff --git a/include/fmt/printf.h b/include/fmt/printf.h index 5a396964..bf4a293b 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -52,7 +52,6 @@ class printf_precision_handler: public function { typename std::enable_if::value, int>::type operator()(T) { FMT_THROW(format_error("precision is not integer")); - return 0; } }; @@ -194,7 +193,6 @@ class printf_width_handler: public function { typename std::enable_if::value, unsigned>::type operator()(T) { FMT_THROW(format_error("width is not integer")); - return 0; } }; } // namespace internal diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 3e8480a1..e5dc63f7 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -126,8 +126,38 @@ struct is_tuple_like { is_tuple_like_::value && !is_range_::value; }; -template -void for_each(std::index_sequence, Tuple &&tup, F &&f) noexcept { +// Check for integer_sequence +#if defined(__cpp_lib_integer_sequence) || FMT_MSC_VER >= 1910 +template +using integer_sequence = std::integer_sequence; +template +using index_sequence = std::index_sequence; +template +using make_index_sequence = std::make_index_sequence; +#else +template +struct integer_sequence { + typedef T value_type; + + static FMT_CONSTEXPR std::size_t size() { + return sizeof...(N); + } +}; + +template +using index_sequence = integer_sequence; + +template +struct make_integer_sequence : make_integer_sequence {}; +template +struct make_integer_sequence : integer_sequence {}; + +template +using make_index_sequence = make_integer_sequence; +#endif + +template +void for_each(index_sequence, Tuple &&tup, F &&f) noexcept { using std::get; // using free function get(T) now. const int _[] = {0, ((void)f(get(tup)), 0)...}; @@ -135,7 +165,7 @@ void for_each(std::index_sequence, Tuple &&tup, F &&f) noexcept { } template -FMT_CONSTEXPR std::make_index_sequence::value> +FMT_CONSTEXPR make_index_sequence::value> get_indexes(T const &) { return {}; } template diff --git a/include/fmt/time.h b/include/fmt/time.h index 5976ea6e..7ca967f6 100644 --- a/include/fmt/time.h +++ b/include/fmt/time.h @@ -54,7 +54,6 @@ inline std::tm localtime(std::time_t time) { return lt.tm_; // Too big time values may be unsupported. FMT_THROW(format_error("time_t value out of range")); - return std::tm(); } // Thread-safe replacement for std::gmtime @@ -90,7 +89,6 @@ inline std::tm gmtime(std::time_t time) { return gt.tm_; // Too big time values may be unsupported. FMT_THROW(format_error("time_t value out of range")); - return std::tm(); } namespace internal { diff --git a/support/appveyor.yml b/support/appveyor.yml index cc5ef9a9..ede92196 100644 --- a/support/appveyor.yml +++ b/support/appveyor.yml @@ -1,4 +1,6 @@ -configuration: Debug +configuration: + - Debug + - Release clone_depth: 1 @@ -32,7 +34,7 @@ before_build: - mkdir build - cd build - - ps: cmake -G "$($env:CMAKE_GENERATOR)$($env:CMAKE_GENERATOR_SUFFIX)" -DFMT_WERROR=OFF -DFMT_PEDANTIC=ON -DCMAKE_BUILD_TYPE=Debug .. + - ps: cmake -G "$($env:CMAKE_GENERATOR)$($env:CMAKE_GENERATOR_SUFFIX)" -DFMT_WERROR=OFF -DFMT_PEDANTIC=ON -DCMAKE_BUILD_TYPE="$($env:configuration)" .. build: project: C:\projects\fmt\build\fmt.sln @@ -42,7 +44,7 @@ build: test_script: - ps: | New-Item .\DartConfiguration.tcl -ItemType file - ctest -C Debug -T Test + ctest -C "$($env:configuration)" -T Test $XSLInputElement = New-Object System.Xml.Xsl.XslCompiledTransform $XslInputElement.Load("https://raw.githubusercontent.com/rpavlik/jenkins-ctest-plugin/master/ctest-to-junit.xsl") $file = $(ls Testing\*\Test.xml) | Select -first 1 diff --git a/test/format-impl-test.cc b/test/format-impl-test.cc index 79ddd396..d7511cd0 100644 --- a/test/format-impl-test.cc +++ b/test/format-impl-test.cc @@ -30,9 +30,8 @@ struct ValueExtractor: fmt::internal::function { } template - T operator()(U) { + FMT_NORETURN T operator()(U) { throw std::runtime_error(fmt::format("invalid type {}", typeid(U).name())); - return T(); } }; diff --git a/test/gtest-extra-test.cc b/test/gtest-extra-test.cc index 53f0a0d6..2043f549 100644 --- a/test/gtest-extra-test.cc +++ b/test/gtest-extra-test.cc @@ -195,39 +195,33 @@ TEST(ExpectSystemErrorTest, DoesNotGenerateUnreachableCodeWarning) { } TEST(AssertionSyntaxTest, ExceptionAssertionBehavesLikeSingleStatement) { - if (::testing::internal::AlwaysFalse()) { + if (::testing::internal::AlwaysFalse()) EXPECT_THROW_MSG(do_nothing(), std::exception, ""); - } - if (::testing::internal::AlwaysTrue()) { + if (::testing::internal::AlwaysTrue()) EXPECT_THROW_MSG(throw_exception(), std::exception, "test"); - } else { + else do_nothing(); - } } TEST(AssertionSyntaxTest, SystemErrorAssertionBehavesLikeSingleStatement) { - if (::testing::internal::AlwaysFalse()) { + if (::testing::internal::AlwaysFalse()) EXPECT_SYSTEM_ERROR(do_nothing(), EDOM, ""); - } - if (::testing::internal::AlwaysTrue()) { + if (::testing::internal::AlwaysTrue()) EXPECT_SYSTEM_ERROR(throw_system_error(), EDOM, "test"); - } else { + else do_nothing(); - } } TEST(AssertionSyntaxTest, WriteAssertionBehavesLikeSingleStatement) { - if (::testing::internal::AlwaysFalse()) { + if (::testing::internal::AlwaysFalse()) EXPECT_WRITE(stdout, std::printf("x"), "x"); - } - if (::testing::internal::AlwaysTrue()) { + if (::testing::internal::AlwaysTrue()) EXPECT_WRITE(stdout, std::printf("x"), "x"); - } else { + else do_nothing(); - } } // Tests EXPECT_THROW_MSG. diff --git a/test/util-test.cc b/test/util-test.cc index a9329a38..b22aa0ed 100644 --- a/test/util-test.cc +++ b/test/util-test.cc @@ -822,7 +822,8 @@ TEST(UtilTest, FormatLongWindowsError) { const int provisioning_not_allowed = 0x80284013L /*TBS_E_PROVISIONING_NOT_ALLOWED*/; if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, - provisioning_not_allowed, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + static_cast(provisioning_not_allowed), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast(&message), 0, 0) == 0) { return; }