Reliably diagnose stack allocations in C++/WinRT#329
Merged
Conversation
Member
|
Port to cppx |
Contributor
Author
|
I have a few things lined up where cppwinrt and cppx have diverged and I'm preparing a PR to bring them all in. |
Scottj1s
reviewed
Apr 19, 2019
| } | ||
|
|
||
| #ifdef _DEBUG | ||
| void use_make_function_to_create_this_object() final |
Member
There was a problem hiding this comment.
Can we issue a static_assert and more friendly message instead?
Contributor
Author
There was a problem hiding this comment.
Sadly I haven't found a way to express this with a static_assert.
Scottj1s
approved these changes
Apr 19, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I previously introduced a runtime assertion to help diagnose and catch stack allocation bugs in C++/WinRT. Unfortunately, there are just too many cases where this does not catch stack allocations. Notably, if the local is created within a coroutine frame then it won't detect it since the coroutine frame is itself allocated on the heap. This update turns this runtime assertion into a compiler error that should catch such mistakes in all cases.
Double clicking on the error brings the developer to this helpful comment:
This does mean that private destructors aren't supported, but that's already a requirement if you want to use the
final_releasefeature (deferred destruction) and the only reason you'd want a private destructor is to prevent someone from accidentally callingdelete ptrand C++/WinRT makes that quite hard to do since you really have to go out of your way to get hold of a raw pointer in C++/WinRT. C++/WinRT then also ensures that all implementations arefinal, which provides the C++ optimizer the possibility to devirtualize further.