From b5b9317a3c1b794b0cd1087a4b4076fc2c278dee Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Thu, 2 Oct 2025 12:30:55 -0400 Subject: [PATCH] Warn about unsafe use of join --- include/fmt/ranges.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 24c61e93..5a3412ef 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -18,6 +18,12 @@ #include "format.h" +#if FMT_HAS_CPP_ATTRIBUTE(clang::lifetimebound) +# define FMT_LIFETIMEBOUND [[clang::lifetimebound]] +#else +# define FMT_LIFETIMEBOUND +#endif + FMT_BEGIN_NAMESPACE FMT_EXPORT @@ -821,12 +827,12 @@ auto join(Range&& r, string_view sep) * * **Example**: * - * auto t = std::tuple{1, 'a'}; + * auto t = std::tuple(1, 'a'); * fmt::print("{}", fmt::join(t, ", ")); * // Output: 1, a */ template ::value)> -FMT_CONSTEXPR auto join(const Tuple& tuple, string_view sep) +FMT_CONSTEXPR auto join(const Tuple& tuple FMT_LIFETIMEBOUND, string_view sep) -> tuple_join_view { return {tuple, sep}; }