diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 0a1dab31..b65bdfad 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -348,32 +348,32 @@ FMT_CONSTEXPR const Char* parse_chrono_format(const Char* begin, } struct chrono_format_checker { - void report_no_date() { FMT_THROW(format_error("no date")); } + FMT_NORETURN void report_no_date() { FMT_THROW(format_error("no date")); } template void on_text(const Char*, const Char*) {} - void on_abbr_weekday() { report_no_date(); } - void on_full_weekday() { report_no_date(); } - void on_dec0_weekday(numeric_system) { report_no_date(); } - void on_dec1_weekday(numeric_system) { report_no_date(); } - void on_abbr_month() { report_no_date(); } - void on_full_month() { report_no_date(); } + FMT_NORETURN void on_abbr_weekday() { report_no_date(); } + FMT_NORETURN void on_full_weekday() { report_no_date(); } + FMT_NORETURN void on_dec0_weekday(numeric_system) { report_no_date(); } + FMT_NORETURN void on_dec1_weekday(numeric_system) { report_no_date(); } + FMT_NORETURN void on_abbr_month() { report_no_date(); } + FMT_NORETURN void on_full_month() { report_no_date(); } void on_24_hour(numeric_system) {} void on_12_hour(numeric_system) {} void on_minute(numeric_system) {} void on_second(numeric_system) {} - void on_datetime(numeric_system) { report_no_date(); } - void on_loc_date(numeric_system) { report_no_date(); } - void on_loc_time(numeric_system) { report_no_date(); } - void on_us_date() { report_no_date(); } - void on_iso_date() { report_no_date(); } + FMT_NORETURN void on_datetime(numeric_system) { report_no_date(); } + FMT_NORETURN void on_loc_date(numeric_system) { report_no_date(); } + FMT_NORETURN void on_loc_time(numeric_system) { report_no_date(); } + FMT_NORETURN void on_us_date() { report_no_date(); } + FMT_NORETURN void on_iso_date() { report_no_date(); } void on_12_hour_time() {} void on_24_hour_time() {} void on_iso_time() {} void on_am_pm() {} void on_duration_value() {} void on_duration_unit() {} - void on_utc_offset() { report_no_date(); } - void on_tz_name() { report_no_date(); } + FMT_NORETURN void on_utc_offset() { report_no_date(); } + FMT_NORETURN void on_tz_name() { report_no_date(); } }; template inline int to_int(Int value) { diff --git a/include/fmt/core.h b/include/fmt/core.h index 8733b427..fe2586b5 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -143,6 +143,12 @@ # endif #endif +#if FMT_EXCEPTIONS && FMT_HAS_CPP_ATTRIBUTE(noreturn) +# define FMT_NORETURN [[noreturn]] +#else +# define FMT_NORETURN +#endif + #ifndef FMT_DEPRECATED # if (FMT_HAS_CPP_ATTRIBUTE(deprecated) && __cplusplus >= 201402L) || \ FMT_MSC_VER >= 1900 @@ -350,7 +356,7 @@ struct error_handler { FMT_CONSTEXPR error_handler(const error_handler&) {} // This function is intentionally not constexpr to give a compile-time error. - FMT_API void on_error(const char* message); + FMT_API FMT_NORETURN void on_error(const char* message); }; // GCC 4.6.x cannot expand `T...`. diff --git a/include/fmt/format.h b/include/fmt/format.h index 1582625a..ee6ec500 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2621,7 +2621,7 @@ template class basic_writer { num_writer{abs_value, size, sep}); } - void on_error() { FMT_THROW(format_error("invalid type specifier")); } + FMT_NORETURN void on_error() { FMT_THROW(format_error("invalid type specifier")); } }; // Writes a formatted integer. @@ -2858,7 +2858,7 @@ struct float_spec_handler { if (type == 'A') upper = true; } - void on_error() { FMT_THROW(format_error("invalid type specifier")); } + FMT_NORETURN void on_error() { FMT_THROW(format_error("invalid type specifier")); } }; template diff --git a/test/format-impl-test.cc b/test/format-impl-test.cc index 6d35b204..6f48aee3 100644 --- a/test/format-impl-test.cc +++ b/test/format-impl-test.cc @@ -22,12 +22,6 @@ #undef max -#if FMT_HAS_CPP_ATTRIBUTE(noreturn) -# define FMT_NORETURN [[noreturn]] -#else -# define FMT_NORETURN -#endif - using fmt::internal::fp; template void test_construct_from_double() { diff --git a/test/gtest-extra-test.cc b/test/gtest-extra-test.cc index dd2ba2af..eee949a2 100644 --- a/test/gtest-extra-test.cc +++ b/test/gtest-extra-test.cc @@ -52,9 +52,9 @@ int SingleEvaluationTest::b_; void do_nothing() {} -void throw_exception() { throw std::runtime_error("test"); } +FMT_NORETURN void throw_exception() { throw std::runtime_error("test"); } -void throw_system_error() { throw fmt::system_error(EDOM, "test"); } +FMT_NORETURN void throw_system_error() { throw fmt::system_error(EDOM, "test"); } // Tests that when EXPECT_THROW_MSG fails, it evaluates its message argument // exactly once.