Skip to content

Commit a73d89e

Browse files
committed
Catch invalid uses of fmt::arg
1 parent cb8e7ca commit a73d89e

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

include/fmt/core.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,10 @@ template <typename Char> struct named_arg_base {
13961396
}
13971397
};
13981398

1399-
template <typename T, typename Char> struct named_arg : named_arg_base<Char> {
1399+
struct view {};
1400+
1401+
template <typename T, typename Char>
1402+
struct named_arg : view, named_arg_base<Char> {
14001403
const T& value;
14011404

14021405
named_arg(basic_string_view<Char> name, const T& val)
@@ -1414,7 +1417,6 @@ inline void check_format_string(const S&) {
14141417
template <typename..., typename S, FMT_ENABLE_IF(is_compile_string<S>::value)>
14151418
void check_format_string(S);
14161419

1417-
struct view {};
14181420
template <bool...> struct bool_pack;
14191421
template <bool... Args>
14201422
using all_true =
@@ -1443,13 +1445,8 @@ typename buffer_context<Char>::iterator vformat_to(
14431445

14441446
/**
14451447
\rst
1446-
Returns a named argument to be used in a formatting function.
1447-
1448-
The named argument holds a reference and does not extend the lifetime
1449-
of its arguments.
1450-
Consequently, a dangling reference can accidentally be created.
1451-
The user should take care to only pass this function temporaries when
1452-
the named argument is itself a temporary, as per the following example.
1448+
Returns a named argument to be used in a formatting function. It should only
1449+
be used in a call to a formatting function.
14531450
14541451
**Example**::
14551452

0 commit comments

Comments
 (0)