Skip to content

Commit

Permalink
A little more self-hosting: meta::object_declaration to Cpp2
Browse files Browse the repository at this point in the history
And fix a bug this exposed - generated `operator=` memberwise emitted wrong syntax for a base type... previous test cases did not have copyable base types, but `cpp2::meta` embraces copyable base types as a design choice which is find because they aren't polymorphic in the usual inheritance sense
  • Loading branch information
hsutter committed May 7, 2023
1 parent a2a6f04 commit 59fc520
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 71 deletions.
2 changes: 1 addition & 1 deletion regression-tests/test-results/version
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

cppfront compiler v0.2.1 Build 8507:0751
cppfront compiler v0.2.1 Build 8507:1428
Copyright(c) Herb Sutter All rights reserved

SPDX-License-Identifier: CC-BY-NC-ND-4.0
Expand Down
13 changes: 10 additions & 3 deletions source/cppfront.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4497,17 +4497,24 @@ class cppfront

// Otherwise, use a default... for a non-copy/move that's the member initializer
// (for which we don't need to emit anything special because it will get used),
// and for a copy/move function we default to "= that.same_member"
// and for a copy/move function we default to "= that.same_member" (or, if this
// is a base type, just "= that")

This comment has been minimized.

Copy link
@JohelEGP

JohelEGP May 8, 2023

Contributor

just "= that"

is wrong.
Similar to #402 (comment),
a templated assignment can be chosen over copy/move assignment.

if (!found_explicit_init)
{
if (emitting_move_that_function)
{
initializer = "std::move(that)." + object_name;
initializer = "std::move(that)";
if (!(*object)->has_name("this")) {
initializer += "." + object_name;
}
found_default_init = true;
}
else if (emitting_that_function)
{
initializer = "that." + object_name;
initializer = "that";
if (!(*object)->has_name("this")) {
initializer += "." + object_name;
}
found_default_init = true;
}
else if ((*object)->initializer)
Expand Down
Loading

0 comments on commit 59fc520

Please sign in to comment.