Skip to content

Commit eac30d8

Browse files
committed
Don't generate a converting assignment operator if the user wrote one, closes #468
1 parent 2a7c583 commit eac30d8

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

source/cppfront.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -5468,6 +5468,7 @@ class cppfront
54685468
(
54695469
n.is_constructor()
54705470
&& !n.is_constructor_with_that()
5471+
&& !contains( current_functions.back().declared_that_functions.assignments_from, n.nth_parameter_type_name(2) )
54715472
)
54725473
)
54735474
{

source/parse.h

+32-4
Original file line numberDiff line numberDiff line change
@@ -2058,6 +2058,9 @@ struct function_type_node
20582058
return false;
20592059
}
20602060

2061+
auto nth_parameter_type_name(int n) const
2062+
-> std::string;
2063+
20612064
auto has_in_parameter_named(std::string_view s) const
20622065
-> bool
20632066
{
@@ -2469,6 +2472,15 @@ struct declaration_node
24692472
return std::get<a_function>(type)->has_move_parameter_named(s);
24702473
}
24712474

2475+
auto nth_parameter_type_name(int n) const
2476+
-> std::string
2477+
{
2478+
if (!is_function()) {
2479+
return "";
2480+
}
2481+
return std::get<a_function>(type)->nth_parameter_type_name(n);
2482+
}
2483+
24722484
auto is_global () const -> bool
24732485
{ return !parent_declaration; }
24742486

@@ -2864,10 +2876,11 @@ struct declaration_node
28642876
}
28652877

28662878
struct declared_that_funcs {
2867-
declaration_node const* out_this_in_that = {};
2868-
declaration_node const* out_this_move_that = {};
2869-
declaration_node const* inout_this_in_that = {};
2870-
declaration_node const* inout_this_move_that = {};
2879+
declaration_node const* out_this_in_that = {};
2880+
declaration_node const* out_this_move_that = {};
2881+
declaration_node const* inout_this_in_that = {};
2882+
declaration_node const* inout_this_move_that = {};
2883+
std::vector<std::string> assignments_from = {};
28712884
};
28722885

28732886
auto find_declared_that_functions() const
@@ -2898,6 +2911,9 @@ struct declaration_node
28982911
if (decl->is_assignment_with_move_that()) {
28992912
ret.inout_this_move_that = decl;
29002913
}
2914+
if (decl->is_assignment() && !decl->is_assignment_with_that()) {
2915+
ret.assignments_from.emplace_back( decl->nth_parameter_type_name(2) );
2916+
}
29012917
}
29022918
}
29032919

@@ -3083,6 +3099,18 @@ auto parameter_declaration_node::has_name(std::string_view s) const
30833099
}
30843100

30853101

3102+
auto function_type_node::nth_parameter_type_name(int n) const
3103+
-> std::string
3104+
{
3105+
if (std::ssize(parameters->parameters) >= n)
3106+
{
3107+
return parameters->parameters[n-1]->declaration->get_object_type()->to_string();
3108+
}
3109+
// Else
3110+
return "";
3111+
}
3112+
3113+
30863114
auto function_type_node::is_function_with_this() const
30873115
-> bool
30883116
{

0 commit comments

Comments
 (0)