-
Notifications
You must be signed in to change notification settings - Fork 259
[BUG] Emitted code relies on implicit move and copy constructors, but move and copy constructors are marked explicit
#375
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
Comments
There are at least two issues here.
Both issues are harmful as they impact performance without bringing any value. Just because the performance is already broken, you can overcome the current limitations by explicitly calling a constructor - the impact will be the same as with an implicit constructor and move-from-last. I'm not too fond of making constructors implicit by default - I hope we can find a solution that will not suppress copy elision. We can mimic copy elision on the cpp2 side, but it will impact the cpp1 code. |
And interferes with implicit moves, which actually does OR, and so the explicit move can result in a hard error. |
Re constructors: My intent was that Re move from last use: That should be suppressed when the last use is the beginning of a |
Only when the operand is exactly the name of a non-parameter local.
I remember reading that implementations reliably apply this optimization. |
Yes, that would address the problem and is what I was trying to achieve with the proposed change. If it's the right thing to do, I'd be happy to create a pull request with the change and an accompanying test case? |
I was making another change anyway so I just did it while I was in the file. Thanks again for pointing this out! |
closes hsutter#375 Generated code now doesn't get tacked together as a very long emitted line - which is legal code, but isn't visually pleasing or readable. This matters more in this commit now that we have meta functions that generate multiple functions in the same type.
Describe the bug
cppfront is emitting the
explicit
specifier on all single argument constructors including move and copy constructors. At the same time implicit move and copy are being used by code that is emitted - for instance - when returning named values from functions.To Reproduce
Steps to reproduce the behavior:
Here is a Compiler Explorer link demonstrating the problem: https://godbolt.org/z/x8T4ec7Wd
Note how
foo
's move and copy constructors are explicit, but the call toget_foo()
inmain
would need at least an implicit copy constructor.Calling cppfront with -p and compiling the result with gcc-12
I would expect copy and move constructors to not be
explicit
Copy and move constructors are marked
explicit
Additional context
I have resolved this issue locally by only emitting the
explicit
specifier if the constructor does not have athat
:The text was updated successfully, but these errors were encountered: