From 1057379edf7a4177d003ad61f214731012265985 Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Sun, 26 Dec 2021 21:15:03 +0500 Subject: [PATCH 1/2] Fix throw with exceptions disabled --- include/fmt/chrono.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 85680b3b56ec..31fee070afd9 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -1404,7 +1404,7 @@ inline Int to_nonnegative_int(T value, Int upper) { template ::value)> inline Int to_nonnegative_int(T value, Int upper) { if (value < 0 || value > static_cast(upper)) - throw format_error("invalid value"); + FMT_THROW(format_error("invalid value")); return static_cast(value); } From d1c400e8cf6203473510609bfebecf38a3454a2b Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Sun, 26 Dec 2021 22:14:49 +0500 Subject: [PATCH 2/2] Improve noexception test --- test/CMakeLists.txt | 2 +- test/noexception-test.cc | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/noexception-test.cc diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c75c4f28389e..c42037725fde 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -144,7 +144,7 @@ if (FMT_PEDANTIC) check_cxx_compiler_flag(-fno-exceptions HAVE_FNO_EXCEPTIONS_FLAG) endif () if (HAVE_FNO_EXCEPTIONS_FLAG) - add_library(noexception-test ../src/format.cc) + add_library(noexception-test ../src/format.cc noexception-test.cc) target_include_directories( noexception-test PRIVATE ${PROJECT_SOURCE_DIR}/include) target_compile_options(noexception-test PRIVATE -fno-exceptions) diff --git a/test/noexception-test.cc b/test/noexception-test.cc new file mode 100644 index 000000000000..bf3472fd1013 --- /dev/null +++ b/test/noexception-test.cc @@ -0,0 +1,18 @@ +// Formatting library for C++ - Noexception tests +// +// Copyright (c) 2012 - present, Victor Zverovich +// All rights reserved. +// +// For the license information refer to format.h. + +#include "fmt/args.h" +#include "fmt/chrono.h" +#include "fmt/color.h" +#include "fmt/compile.h" +#include "fmt/core.h" +#include "fmt/format.h" +#include "fmt/os.h" +#include "fmt/ostream.h" +#include "fmt/printf.h" +#include "fmt/ranges.h" +#include "fmt/xchar.h"