-
-
Notifications
You must be signed in to change notification settings - Fork 668
Fix Issue 19415 - return non-copyable struct fails if member function has return attribute #8983
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
Conversation
|
Thanks for your pull request and interest in making D better, @RazvanN7! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + dmd#8983" |
|
Wow, thanks for finding that so quickly! |
|
Seems to fail for 64-bit builds, but when I look at the log, I can't figure out why. Looks like linker errors, but no actual message. Seems like it's |
|
You have the issue number messed up, should be 19415, not 19145. |
|
I would be nice to have the PR description i the commit message. Doing that from the beginning would automatically add the commit message as the PR description. |
2ceee36 to
d70d410
Compare
I found a better fix. It seems like StructDeclaration.size() was used abusively to check for forward references. I added the single check; this is correct and even more efficient.
Fixed.
I think it would be a bit too verbose. |
… has return attribute
d70d410 to
487a8c5
Compare
|
cc @WalterBright as it was your PR that introduced this bug : #8346 |
When
struct Sis semantically analyzed, the field StructDeclaration.postblit is null. Before actually building the postblit and setting StructDeclaration.postblit to point to it, all the members ofstruct Sare semantically analyzed. This results in the fact that at the time when foo is analyzed, the struct does not appear to have a postblit. During the semantic analysis of foo, this line [1] is executed in order to delete thereturnattribute from the function. The code path is : TypeStruct.hasPointers() -> AggregateDeclaration.size() -> AggregateDeclaration.determineSize() -> StructDeclaration.finalizeSize(). At the end of finalizeSize this is done: [2]. The code path is: toArgTypes -> StructDeclaration.isPOD. Although the struct is not pod because it has a postblit, because the struct has not been semantically analyzed completely, it appears as it is POD, messing with the size of the struct and ultimately making it wrongfully not usable with NRVO.The fix makes it so that AggregateDeclaration.size() is not called anymore to verify forward references. This should also improve performance since a lot of unnecessary checks are avoided.
This has truly been an adventure.
[1] https://github.com/dlang/dmd/pull/8346/files#diff-64d4abe08ba2355c2b95cb22e46b8572R876
[2] https://github.com/dlang/dmd/blob/master/src/dmd/dstruct.d#L429