Skip to content

Commit 1e217ad

Browse files
committed
Fix infinite recursion in std::swap from move assignment
1 parent 87d3c20 commit 1e217ad

File tree

9 files changed

+94
-83
lines changed

9 files changed

+94
-83
lines changed

samples/client/multiple/MultipleQueriesClient.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,10 @@ CompleteTaskInput& CompleteTaskInput::operator=(const CompleteTaskInput& other)
165165

166166
CompleteTaskInput& CompleteTaskInput::operator=(CompleteTaskInput&& other) noexcept
167167
{
168-
CompleteTaskInput value { std::move(other) };
169-
170-
std::swap(*this, value);
168+
id = std::move(other.id);
169+
testTaskState = std::move(other.testTaskState);
170+
isComplete = std::move(other.isComplete);
171+
clientMutationId = std::move(other.clientMutationId);
171172

172173
return *this;
173174
}

samples/client/mutate/MutateClient.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ CompleteTaskInput& CompleteTaskInput::operator=(const CompleteTaskInput& other)
9898

9999
CompleteTaskInput& CompleteTaskInput::operator=(CompleteTaskInput&& other) noexcept
100100
{
101-
CompleteTaskInput value { std::move(other) };
102-
103-
std::swap(*this, value);
101+
id = std::move(other.id);
102+
testTaskState = std::move(other.testTaskState);
103+
isComplete = std::move(other.isComplete);
104+
clientMutationId = std::move(other.clientMutationId);
104105

105106
return *this;
106107
}

samples/client/nestedinput/NestedInputClient.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ InputA& InputA::operator=(const InputA& other)
7373

7474
InputA& InputA::operator=(InputA&& other) noexcept
7575
{
76-
InputA value { std::move(other) };
77-
78-
std::swap(*this, value);
76+
a = std::move(other.a);
7977

8078
return *this;
8179
}
@@ -107,9 +105,7 @@ InputB& InputB::operator=(const InputB& other)
107105

108106
InputB& InputB::operator=(InputB&& other) noexcept
109107
{
110-
InputB value { std::move(other) };
111-
112-
std::swap(*this, value);
108+
b = std::move(other.b);
113109

114110
return *this;
115111
}
@@ -153,9 +149,10 @@ InputABCD& InputABCD::operator=(const InputABCD& other)
153149

154150
InputABCD& InputABCD::operator=(InputABCD&& other) noexcept
155151
{
156-
InputABCD value { std::move(other) };
157-
158-
std::swap(*this, value);
152+
d = std::move(other.d);
153+
a = std::move(other.a);
154+
b = std::move(other.b);
155+
bc = std::move(other.bc);
159156

160157
return *this;
161158
}
@@ -191,9 +188,8 @@ InputBC& InputBC::operator=(const InputBC& other)
191188

192189
InputBC& InputBC::operator=(InputBC&& other) noexcept
193190
{
194-
InputBC value { std::move(other) };
195-
196-
std::swap(*this, value);
191+
c = std::move(other.c);
192+
b = std::move(other.b);
197193

198194
return *this;
199195
}

samples/learn/schema/StarWarsSchema.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@ ReviewInput& ReviewInput::operator=(const ReviewInput& other)
127127

128128
ReviewInput& ReviewInput::operator=(ReviewInput&& other) noexcept
129129
{
130-
ReviewInput value { std::move(other) };
131-
132-
std::swap(*this, value);
130+
stars = std::move(other.stars);
131+
commentary = std::move(other.commentary);
133132

134133
return *this;
135134
}

samples/today/nointrospection/TodaySchema.cpp

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,10 @@ CompleteTaskInput& CompleteTaskInput::operator=(const CompleteTaskInput& other)
266266

267267
CompleteTaskInput& CompleteTaskInput::operator=(CompleteTaskInput&& other) noexcept
268268
{
269-
CompleteTaskInput value { std::move(other) };
270-
271-
std::swap(*this, value);
269+
id = std::move(other.id);
270+
testTaskState = std::move(other.testTaskState);
271+
isComplete = std::move(other.isComplete);
272+
clientMutationId = std::move(other.clientMutationId);
272273

273274
return *this;
274275
}
@@ -304,9 +305,8 @@ ThirdNestedInput& ThirdNestedInput::operator=(const ThirdNestedInput& other)
304305

305306
ThirdNestedInput& ThirdNestedInput::operator=(ThirdNestedInput&& other) noexcept
306307
{
307-
ThirdNestedInput value { std::move(other) };
308-
309-
std::swap(*this, value);
308+
id = std::move(other.id);
309+
second = std::move(other.second);
310310

311311
return *this;
312312
}
@@ -338,9 +338,7 @@ FourthNestedInput& FourthNestedInput::operator=(const FourthNestedInput& other)
338338

339339
FourthNestedInput& FourthNestedInput::operator=(FourthNestedInput&& other) noexcept
340340
{
341-
FourthNestedInput value { std::move(other) };
342-
343-
std::swap(*this, value);
341+
id = std::move(other.id);
344342

345343
return *this;
346344
}
@@ -372,9 +370,7 @@ IncludeNullableSelfInput& IncludeNullableSelfInput::operator=(const IncludeNulla
372370

373371
IncludeNullableSelfInput& IncludeNullableSelfInput::operator=(IncludeNullableSelfInput&& other) noexcept
374372
{
375-
IncludeNullableSelfInput value { std::move(other) };
376-
377-
std::swap(*this, value);
373+
self = std::move(other.self);
378374

379375
return *this;
380376
}
@@ -406,9 +402,7 @@ IncludeNonNullableListSelfInput& IncludeNonNullableListSelfInput::operator=(cons
406402

407403
IncludeNonNullableListSelfInput& IncludeNonNullableListSelfInput::operator=(IncludeNonNullableListSelfInput&& other) noexcept
408404
{
409-
IncludeNonNullableListSelfInput value { std::move(other) };
410-
411-
std::swap(*this, value);
405+
selves = std::move(other.selves);
412406

413407
return *this;
414408
}
@@ -484,9 +478,18 @@ StringOperationFilterInput& StringOperationFilterInput::operator=(const StringOp
484478

485479
StringOperationFilterInput& StringOperationFilterInput::operator=(StringOperationFilterInput&& other) noexcept
486480
{
487-
StringOperationFilterInput value { std::move(other) };
488-
489-
std::swap(*this, value);
481+
and_ = std::move(other.and_);
482+
or_ = std::move(other.or_);
483+
equal = std::move(other.equal);
484+
notEqual = std::move(other.notEqual);
485+
contains = std::move(other.contains);
486+
notContains = std::move(other.notContains);
487+
in = std::move(other.in);
488+
notIn = std::move(other.notIn);
489+
startsWith = std::move(other.startsWith);
490+
notStartsWith = std::move(other.notStartsWith);
491+
endsWith = std::move(other.endsWith);
492+
notEndsWith = std::move(other.notEndsWith);
490493

491494
return *this;
492495
}
@@ -522,9 +525,8 @@ SecondNestedInput& SecondNestedInput::operator=(const SecondNestedInput& other)
522525

523526
SecondNestedInput& SecondNestedInput::operator=(SecondNestedInput&& other) noexcept
524527
{
525-
SecondNestedInput value { std::move(other) };
526-
527-
std::swap(*this, value);
528+
id = std::move(other.id);
529+
third = std::move(other.third);
528530

529531
return *this;
530532
}
@@ -560,9 +562,8 @@ ForwardDeclaredInput& ForwardDeclaredInput::operator=(const ForwardDeclaredInput
560562

561563
ForwardDeclaredInput& ForwardDeclaredInput::operator=(ForwardDeclaredInput&& other) noexcept
562564
{
563-
ForwardDeclaredInput value { std::move(other) };
564-
565-
std::swap(*this, value);
565+
nullableSelf = std::move(other.nullableSelf);
566+
listSelves = std::move(other.listSelves);
566567

567568
return *this;
568569
}
@@ -602,9 +603,9 @@ FirstNestedInput& FirstNestedInput::operator=(const FirstNestedInput& other)
602603

603604
FirstNestedInput& FirstNestedInput::operator=(FirstNestedInput&& other) noexcept
604605
{
605-
FirstNestedInput value { std::move(other) };
606-
607-
std::swap(*this, value);
606+
id = std::move(other.id);
607+
second = std::move(other.second);
608+
third = std::move(other.third);
608609

609610
return *this;
610611
}

samples/today/schema/TodaySchema.cpp

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,10 @@ CompleteTaskInput& CompleteTaskInput::operator=(const CompleteTaskInput& other)
266266

267267
CompleteTaskInput& CompleteTaskInput::operator=(CompleteTaskInput&& other) noexcept
268268
{
269-
CompleteTaskInput value { std::move(other) };
270-
271-
std::swap(*this, value);
269+
id = std::move(other.id);
270+
testTaskState = std::move(other.testTaskState);
271+
isComplete = std::move(other.isComplete);
272+
clientMutationId = std::move(other.clientMutationId);
272273

273274
return *this;
274275
}
@@ -304,9 +305,8 @@ ThirdNestedInput& ThirdNestedInput::operator=(const ThirdNestedInput& other)
304305

305306
ThirdNestedInput& ThirdNestedInput::operator=(ThirdNestedInput&& other) noexcept
306307
{
307-
ThirdNestedInput value { std::move(other) };
308-
309-
std::swap(*this, value);
308+
id = std::move(other.id);
309+
second = std::move(other.second);
310310

311311
return *this;
312312
}
@@ -338,9 +338,7 @@ FourthNestedInput& FourthNestedInput::operator=(const FourthNestedInput& other)
338338

339339
FourthNestedInput& FourthNestedInput::operator=(FourthNestedInput&& other) noexcept
340340
{
341-
FourthNestedInput value { std::move(other) };
342-
343-
std::swap(*this, value);
341+
id = std::move(other.id);
344342

345343
return *this;
346344
}
@@ -372,9 +370,7 @@ IncludeNullableSelfInput& IncludeNullableSelfInput::operator=(const IncludeNulla
372370

373371
IncludeNullableSelfInput& IncludeNullableSelfInput::operator=(IncludeNullableSelfInput&& other) noexcept
374372
{
375-
IncludeNullableSelfInput value { std::move(other) };
376-
377-
std::swap(*this, value);
373+
self = std::move(other.self);
378374

379375
return *this;
380376
}
@@ -406,9 +402,7 @@ IncludeNonNullableListSelfInput& IncludeNonNullableListSelfInput::operator=(cons
406402

407403
IncludeNonNullableListSelfInput& IncludeNonNullableListSelfInput::operator=(IncludeNonNullableListSelfInput&& other) noexcept
408404
{
409-
IncludeNonNullableListSelfInput value { std::move(other) };
410-
411-
std::swap(*this, value);
405+
selves = std::move(other.selves);
412406

413407
return *this;
414408
}
@@ -484,9 +478,18 @@ StringOperationFilterInput& StringOperationFilterInput::operator=(const StringOp
484478

485479
StringOperationFilterInput& StringOperationFilterInput::operator=(StringOperationFilterInput&& other) noexcept
486480
{
487-
StringOperationFilterInput value { std::move(other) };
488-
489-
std::swap(*this, value);
481+
and_ = std::move(other.and_);
482+
or_ = std::move(other.or_);
483+
equal = std::move(other.equal);
484+
notEqual = std::move(other.notEqual);
485+
contains = std::move(other.contains);
486+
notContains = std::move(other.notContains);
487+
in = std::move(other.in);
488+
notIn = std::move(other.notIn);
489+
startsWith = std::move(other.startsWith);
490+
notStartsWith = std::move(other.notStartsWith);
491+
endsWith = std::move(other.endsWith);
492+
notEndsWith = std::move(other.notEndsWith);
490493

491494
return *this;
492495
}
@@ -522,9 +525,8 @@ SecondNestedInput& SecondNestedInput::operator=(const SecondNestedInput& other)
522525

523526
SecondNestedInput& SecondNestedInput::operator=(SecondNestedInput&& other) noexcept
524527
{
525-
SecondNestedInput value { std::move(other) };
526-
527-
std::swap(*this, value);
528+
id = std::move(other.id);
529+
third = std::move(other.third);
528530

529531
return *this;
530532
}
@@ -560,9 +562,8 @@ ForwardDeclaredInput& ForwardDeclaredInput::operator=(const ForwardDeclaredInput
560562

561563
ForwardDeclaredInput& ForwardDeclaredInput::operator=(ForwardDeclaredInput&& other) noexcept
562564
{
563-
ForwardDeclaredInput value { std::move(other) };
564-
565-
std::swap(*this, value);
565+
nullableSelf = std::move(other.nullableSelf);
566+
listSelves = std::move(other.listSelves);
566567

567568
return *this;
568569
}
@@ -602,9 +603,9 @@ FirstNestedInput& FirstNestedInput::operator=(const FirstNestedInput& other)
602603

603604
FirstNestedInput& FirstNestedInput::operator=(FirstNestedInput&& other) noexcept
604605
{
605-
FirstNestedInput value { std::move(other) };
606-
607-
std::swap(*this, value);
606+
id = std::move(other.id);
607+
second = std::move(other.second);
608+
third = std::move(other.third);
608609

609610
return *this;
610611
}

samples/validation/schema/ValidationSchema.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,8 @@ ComplexInput& ComplexInput::operator=(const ComplexInput& other)
184184

185185
ComplexInput& ComplexInput::operator=(ComplexInput&& other) noexcept
186186
{
187-
ComplexInput value { std::move(other) };
188-
189-
std::swap(*this, value);
187+
name = std::move(other.name);
188+
owner = std::move(other.owner);
190189

191190
return *this;
192191
}

src/ClientGenerator.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -771,10 +771,18 @@ using namespace std::literals;
771771
)cpp" << cppType << R"cpp(& )cpp"
772772
<< cppType << R"cpp(::operator=()cpp" << cppType << R"cpp(&& other) noexcept
773773
{
774-
)cpp" << cppType << R"cpp( value { std::move(other) };
774+
)cpp";
775775

776-
std::swap(*this, value);
776+
for (const auto& inputField : inputType.type->inputFields())
777+
{
778+
const auto name = SchemaLoader::getSafeCppName(inputField->name());
777779

780+
sourceFile << R"cpp( )cpp" << name << R"cpp( = std::move(other.)cpp" << name
781+
<< R"cpp();
782+
)cpp";
783+
}
784+
785+
sourceFile << R"cpp(
778786
return *this;
779787
}
780788
)cpp";

src/SchemaGenerator.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,11 +1594,16 @@ void ModifiedResult<)cpp"
15941594
<< R"cpp(& )cpp" << inputType.cppType << R"cpp(::operator=()cpp"
15951595
<< inputType.cppType << R"cpp(&& other) noexcept
15961596
{
1597-
)cpp" << inputType.cppType
1598-
<< R"cpp( value { std::move(other) };
1597+
)cpp";
15991598

1600-
std::swap(*this, value);
1599+
for (const auto& inputField : inputType.fields)
1600+
{
1601+
sourceFile << R"cpp( )cpp" << inputField.cppName << R"cpp( = std::move(other.)cpp"
1602+
<< inputField.cppName << R"cpp();
1603+
)cpp";
1604+
}
16011605

1606+
sourceFile << R"cpp(
16021607
return *this;
16031608
}
16041609
)cpp";

0 commit comments

Comments
 (0)