From 643fb0662e5edd0fd9646f689589d6cc99bf6433 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 27 Sep 2017 21:18:37 -0700 Subject: [PATCH] Check for argument indexing switch --- fmt/format.h | 1 + test/format-test.cc | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/fmt/format.h b/fmt/format.h index 0035fa4e..5c527a4e 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -3296,6 +3296,7 @@ class dynamic_specs_handler : template arg_ref_type make_arg_ref(Id arg_id) { + context_.check_arg_id(arg_id); return arg_ref_type(arg_id); } diff --git a/test/format-test.cc b/test/format-test.cc index f50f1b3d..b1156108 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1562,6 +1562,10 @@ TEST(FormatTest, DynamicFormatter) { EXPECT_EQ("42", format("{:d}", num)); EXPECT_EQ("foo", format("{:s}", str)); EXPECT_EQ(" 42 foo ", format("{:{}} {:{}}", num, 3, str, 4)); + EXPECT_THROW_MSG(format("{0:{}}", num), + format_error, "cannot switch from manual to automatic argument indexing"); + EXPECT_THROW_MSG(format("{:{0}}", num), + format_error, "cannot switch from automatic to manual argument indexing"); EXPECT_THROW_MSG(format("{:=}", str), format_error, "format specifier '=' requires numeric argument"); EXPECT_THROW_MSG(format("{:+}", str),