Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable [[noreturn]] some. #1107

Merged
merged 1 commit into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions include/fmt/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename Char> 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 <typename Int> inline int to_int(Int value) {
Expand Down
8 changes: 7 additions & 1 deletion include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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...`.
Expand Down
4 changes: 2 additions & 2 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -2621,7 +2621,7 @@ template <typename Range> 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.
Expand Down Expand Up @@ -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 <typename Range>
Expand Down
6 changes: 0 additions & 6 deletions test/format-impl-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <bool is_iec559> void test_construct_from_double() {
Expand Down
4 changes: 2 additions & 2 deletions test/gtest-extra-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down