Skip to content

Instantly share code, notes, and snippets.

@Cannedfood
Last active September 29, 2018 06:38
Show Gist options
  • Save Cannedfood/34db3273dee298d8f4802cba26e063a8 to your computer and use it in GitHub Desktop.
Save Cannedfood/34db3273dee298d8f4802cba26e063a8 to your computer and use it in GitHub Desktop.
Important unit tests for your shared_ptr implementation:
- 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