-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang-cpp] Add delegating constructors #1754
[clang-cpp] Add delegating constructors #1754
Conversation
I believe you forgot the lvalue, in this goto functions you can see that a (c:@S@a@F@a#):
// 22 file main.cpp line 9 column 9 function a
a tmp$1;
// 23 file main.cpp line 9 column 9 function a
tmp$1=NONDET(struct);
// 24
FUNCTION_CALL: a(&tmp$1, 2.000000)
// 25
tmp$1; <------here
// 26 no location
FUNCTION_CALL: ~a(&tmp$1)
// 27 file main.cpp line 11 column 3 function a
dead tmp$1;
// 28 file main.cpp line 11 column 3 function a
END_FUNCTION // a
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ You can compare it with the right one: a third;
// 35 file main.cpp line 17 column 5 function main
a tmp$2;
// 36 file main.cpp line 17 column 5 function main
tmp$2=NONDET(struct);
// 37
FUNCTION_CALL: a(&tmp$2)
// 38 file main.cpp line 17 column 3 function main
third=tmp$2; |
else if (init->isDelegatingInitializer()) | ||
{ | ||
if (get_expr(*init->getInit(), initializer)) | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, it might be missing the assign exprt
.
like this:
initializer = side_effect_exprt("assign", lhs.type());
initializer.copy_to_operands(lhs, rhs);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And what would be the lhs
?
Using this
would feel a bit weird.
1c8fd89
to
59f94d5
Compare
I implemented this by basically copying the code that handles calls to the base from derived ctors and modified it for delegating ctors: https://github.com/esbmc/esbmc/pull/1754/files#diff-784347884400427356b283749ef36cc6e458d4d4df4f8e3a2a4007244a637b1eL976-L981 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you @intrigus-lgtm. Though I'm a bit concerned about the increasing complexity for constructors and member initialization. Might need to start a design phase to investigate a less intertwined solution.
@fbrausse it should be possible to more or less merge the base-derived stuff and delegating stuff. I can do this in this PR if you want. |
Interesting. I'd imagined that the base-derived stuff (which should be invoked recursively, and in addition in a sequence for all the base classes, which it doesn't do right now, I believe) was sufficiently different from delegating. And delegations could also take multiple levels, with each having their own body. Probably best to experiment with that in another PR. I'm happy with it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting this PR, @intrigus-lgtm.
As suggested by @fbrausse, it would be great if you could experiment with the improvement described here in another PR.
THIS DOES NOT CURRENTLY WORK
I tried to support delegating constructors, but the test does not work so I probably did something wrong.
In theory it should be enough to "just" add a call to the constructor we are delegating to, but I didn't get this to work.
Some pointers would be appreciated.
GOTO Program:
SMT constraints