Skip to content

Commit 81a8a11

Browse files
committed
Work around some Clang 19+ issues
Clang 19+ complained about some lambda calls being not constant expressions, so we used named functors. And threw errors at some uses of `std::format()`, which we have replaced with `std::vformat()`.
1 parent 95a3595 commit 81a8a11

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

include/boost/handlebars/dom/function.ipp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ call(Array const& args) const ->
253253
}
254254
}
255255

256+
256257
}
257258

258259
#endif

test/handlebars.cpp

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,18 @@ setup_helpers()
499499
return dom::JSON::stringify(arg);
500500
});
501501

502-
master.hbs.registerHelper("bold", dom::makeVariadicInvocable([](
503-
dom::Array const& args) {
504-
dom::Value options = args.back();
505-
return std::format(R"(<div class="mybold">{}</div>)",
506-
options.get("fn")());
507-
}));
502+
struct BoldHelper
503+
{
504+
auto operator()(dom::Array const & args) const
505+
{
506+
dom::Value options = args.back();
507+
const std::string fmt = R"(<div class="mybold">{}</div>)";
508+
const auto a = toString(options.get("fn")());
509+
return std::vformat(fmt, std::make_format_args(a));
510+
}
511+
};
512+
513+
master.hbs.registerHelper("bold", dom::makeVariadicInvocable(BoldHelper{}));
508514

509515
master.hbs.registerHelper("list", dom::makeVariadicInvocable([](
510516
dom::Array const& args) -> dom::Value {
@@ -679,14 +685,20 @@ master_test()
679685
void
680686
safe_string()
681687
{
682-
Handlebars hbs;
683-
hbs.registerHelper("bold", [](dom::Value str) -> dom::Value
688+
struct BoldHelper
684689
{
685-
if (!str) {
686-
return "bold helper requires at least one argument";
690+
auto operator()(dom::Value str) const -> dom::Value
691+
{
692+
if (!str) {
693+
return "bold helper requires at least one argument";
694+
}
695+
auto args = toString(str);
696+
return std::vformat("<b>{}</b>", std::make_format_args(args));
687697
}
688-
return std::format("<b>{}</b>", str);
689-
});
698+
};
699+
700+
Handlebars hbs;
701+
hbs.registerHelper("bold", BoldHelper{});
690702
std::string templ = "{{bold 'text'}}";
691703
std::string res = hbs.render(templ, {});
692704
BOOST_TEST_NOT(res == "<b>text</b>");
@@ -698,12 +710,19 @@ safe_string()
698710
BOOST_TEST(res == "<b>text</b>");
699711
BOOST_TEST_NOT(res == "&lt;b&gt;text&lt;/b&gt;");
700712

701-
hbs.registerHelper("bold", [](dom::Value str) {
702-
if (!str) {
703-
return safeString("bold helper requires at least one argument");
713+
struct BoldHelper2
714+
{
715+
auto operator()(dom::Value str) const
716+
{
717+
if (!str) {
718+
return safeString("bold helper requires at least one argument");
719+
}
720+
auto args = toString(str);
721+
return safeString(std::vformat("<b>{}</b>", std::make_format_args(args)));
704722
}
705-
return safeString(std::format("<b>{}</b>", str));
706-
});
723+
};
724+
725+
hbs.registerHelper("bold", BoldHelper2{});
707726
res = hbs.render(templ, {});
708727
BOOST_TEST(res == "<b>text</b>");
709728
BOOST_TEST_NOT(res == "&lt;b&gt;text&lt;/b&gt;");

0 commit comments

Comments
 (0)