Skip to content

SharedPtr: add nullptr constructor #12048

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

Merged
merged 1 commit into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions TESTS/mbed_platform/SharedPtr/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void test_single_sharedptr_lifetime()
*/
void test_instance_sharing()
{
SharedPtr<TestStruct> s_ptr1(NULL);
SharedPtr<TestStruct> s_ptr1(nullptr);

// Sanity-check value of counter
TEST_ASSERT_EQUAL(0, TestStruct::s_count);
Expand All @@ -80,7 +80,7 @@ void test_instance_sharing()

TEST_ASSERT_EQUAL(1, TestStruct::s_count);

s_ptr1 = NULL;
s_ptr1 = nullptr;

// Destroy shared pointer
TEST_ASSERT_EQUAL(0, TestStruct::s_count);
Expand Down
7 changes: 7 additions & 0 deletions platform/SharedPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ class SharedPtr {
{
}

/**
* @brief Create empty SharedPtr not pointing to anything.
*/
constexpr SharedPtr(std::nullptr_t) : SharedPtr()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use constexpr to the default constructor as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed.

I'm doing that in #12037 - I've split the PRs cos this one is a breaking change, and that one isn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And, actually, the constexpr here is ineffective until the default constructor it delegates to is made constexpr. But it's harmless if added alone.

{
}

/**
* @brief Create new SharedPtr
* @param ptr Pointer to take control over
Expand Down