Last active
September 29, 2018 06:38
-
-
Save Cannedfood/34db3273dee298d8f4802cba26e063a8 to your computer and use it in GitHub Desktop.
Important unit tests for your shared_ptr implementation:
This file contains 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
- Self assignment: May accidentally destroy the shared_block in the assignment | |
shared<X> a = make_shared<X>(); | |
a = a; | |
- Weak pointer in child: Depending on the implementation, could delete the control block twice. | |
struct Test { | |
weak<Test> self; | |
}; | |
shared<Test> t = make_shared<Test>(); | |
t->self = t; | |
t.reset(); | |
- Feel free to comment if you find other difficult to find things that can go wrong! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment