Skip to content

Commit 0ca8c0f

Browse files
authored
Merge pull request #227 from elbeno/format-spec-mismatch
✅ 🔉 Improve `ct_format` help message
2 parents 3b85a40 + 9e7b7dd commit 0ca8c0f

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

include/stdx/ct_format.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ constexpr auto ct_format = [](auto &&...args) {
221221

222222
using data = detail::fmt_data<Fmt>;
223223

224+
static_assert(data::N == sizeof...(args),
225+
"Format string has a mismatch between the number of format "
226+
"specifiers and arguments.");
227+
224228
[[maybe_unused]] auto const format1 = [&]<std::size_t I>(auto &&arg) {
225229
constexpr auto cts =
226230
detail::to_ct_string<data::splits[I].size()>(data::splits[I]);

test/fail/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ if(${CMAKE_CXX_STANDARD} GREATER_EQUAL 20)
5959

6060
add_fail_tests(
6161
atomic_bool_dec
62+
ct_format_mismatch
6263
dynamic_span_no_ct_capacity
6364
dynamic_container_no_ct_capacity
6465
tuple_index_out_of_bounds

test/fail/ct_format_mismatch.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <stdx/ct_format.hpp>
2+
3+
// EXPECT: mismatch between the number of format specifiers and arguments
4+
5+
auto main() -> int { [[maybe_unused]] auto x = stdx::ct_format<"Hello">(42); }

0 commit comments

Comments
 (0)