Skip to content

Commit 00ef370

Browse files
committed
fix(cpp1): omit UFCS macro if the function is qualified
1 parent cc22ddf commit 00ef370

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

regression-tests/pure2-ufcs-member-access-and-chaining.cpp2

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ main: () -> int = {
1818

1919
_ = (j.i).ufcs();
2020

21+
_ = 42.std::to_string();
22+
2123
42.no_return();
2224
}
2325

regression-tests/test-results/pure2-ufcs-member-access-and-chaining.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@
1313
[[nodiscard]] auto main() -> int;
1414

1515

16-
#line 24 "pure2-ufcs-member-access-and-chaining.cpp2"
16+
#line 26 "pure2-ufcs-member-access-and-chaining.cpp2"
1717
auto no_return([[maybe_unused]] auto const& param1) -> void;
1818

1919
[[nodiscard]] auto ufcs(cpp2::in<int> i) -> int;
2020
struct fun_ret { int i; };
2121

2222

2323

24-
#line 30 "pure2-ufcs-member-access-and-chaining.cpp2"
24+
#line 32 "pure2-ufcs-member-access-and-chaining.cpp2"
2525
[[nodiscard]] auto fun() -> fun_ret;
2626

2727

28-
#line 35 "pure2-ufcs-member-access-and-chaining.cpp2"
28+
#line 37 "pure2-ufcs-member-access-and-chaining.cpp2"
2929
[[nodiscard]] auto get_i(auto const& r) -> int;
3030

3131

32-
#line 39 "pure2-ufcs-member-access-and-chaining.cpp2"
32+
#line 41 "pure2-ufcs-member-access-and-chaining.cpp2"
3333
// And a test for non-local UFCS, which shouldn't do a [&] capture
3434
[[nodiscard]] auto f([[maybe_unused]] auto const& param1) -> int;
3535
extern int y;
@@ -56,6 +56,8 @@ extern int y;
5656

5757
static_cast<void>(CPP2_UFCS(ufcs)((std::move(j).i)));
5858

59+
static_cast<void>(std::to_string(42));
60+
5961
CPP2_UFCS(no_return)(42);
6062
}
6163

@@ -67,7 +69,7 @@ auto no_return([[maybe_unused]] auto const& param1) -> void{}
6769

6870
[[nodiscard]] auto fun() -> fun_ret{
6971
cpp2::deferred_init<int> i;
70-
#line 31 "pure2-ufcs-member-access-and-chaining.cpp2"
72+
#line 33 "pure2-ufcs-member-access-and-chaining.cpp2"
7173
i.construct(42);
7274
return { std::move(i.value()) };
7375
}
@@ -76,7 +78,7 @@ auto no_return([[maybe_unused]] auto const& param1) -> void{}
7678
return r.i;
7779
}
7880

79-
#line 40 "pure2-ufcs-member-access-and-chaining.cpp2"
81+
#line 42 "pure2-ufcs-member-access-and-chaining.cpp2"
8082
[[nodiscard]] auto f([[maybe_unused]] auto const& param1) -> int { return 0; }
8183
int y {CPP2_UFCS_NONLOCAL(f)(0)};
8284

source/cppfront.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -3010,7 +3010,13 @@ class cppfront
30103010

30113011
// Second, emit the UFCS argument list
30123012

3013-
prefix.emplace_back(ufcs_string + "(" + funcname + ")(", args.value().open_pos );
3013+
// If the function name is qualified, omit the UFCS macro entirely.
3014+
if (i->id_expr->is_qualified()) {
3015+
prefix.emplace_back(funcname + "(", args.value().open_pos );
3016+
} else {
3017+
prefix.emplace_back(ufcs_string + "(" + funcname + ")(", args.value().open_pos );
3018+
}
3019+
30143020
suffix.emplace_back(")", args.value().close_pos );
30153021
if (!args.value().text_chunks.empty()) {
30163022
for (auto&& e: args.value().text_chunks) {

0 commit comments

Comments
 (0)