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

Conversation

kjbracey
Copy link
Contributor

@kjbracey kjbracey commented Dec 9, 2019

Summary of changes

For consistency with std::shared_ptr, and mbed::Callback, and as a
potential optimisation aid, give SharedPtr a distinct constructor for
nullptr.

Impact of changes

  • Optimise clearing by adding nullptr overload.

Migration actions required

  • The added nullptr overload means SharedPtr(NULL) or SharedPtr(0) will no longer work; users must use SharedPtr(nullptr) or SharedPtr().

Documentation

Docs example updated in ARMmbed/mbed-os-5-docs#1183


Pull request type

[] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[X] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[X] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers


kjbracey added a commit to kjbracey/mbed-os-5-docs that referenced this pull request Dec 9, 2019
ARMmbed/mbed-os#12048 will require that
`SharedPtr` users use `nullptr` rather than `NULL` or `0`, which
will no longer compile.

Update example in code.

Change can be made to docs whenever, as `nullptr` form works now.
kjbracey added a commit to kjbracey/mbed-os-5-docs that referenced this pull request Dec 9, 2019
ARMmbed/mbed-os#12048 will require that
`SharedPtr` users use `nullptr` rather than `NULL` or `0`, which
will no longer compile.

Update example in code.

Change can be made to docs whenever, as `nullptr` form works now.
kjbracey added a commit to kjbracey/mbed-os-5-docs that referenced this pull request Dec 9, 2019
ARMmbed/mbed-os#12048 will require that
`SharedPtr` users use `nullptr` rather than `NULL` or `0`, which
will no longer compile.

Update example in code.

Change can be made to docs whenever, as `nullptr` form works now.
For consistency with `std::shared_ptr`, and `mbed::Callback`, and as a
potential optimisation aid, give `SharedPtr` a distinct constructor for
`nullptr`.
@ciarmcom ciarmcom requested review from a team December 9, 2019 10:00
@ciarmcom
Copy link
Member

ciarmcom commented Dec 9, 2019

@kjbracey-arm, thank you for your changes.
@ARMmbed/mbed-os-test @ARMmbed/mbed-os-core @ARMmbed/mbed-os-maintainers please review.

@bulislaw
Copy link
Member

Looks good, but it's a breaking change.

/**
* @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.

@0xc0170 0xc0170 added release-version: 6.0.0-alpha-1 First pre-release version of 6.0.0 BREAKING-CHANGE labels Dec 16, 2019
@0xc0170 0xc0170 requested a review from bulislaw December 16, 2019 11:11
@kjbracey
Copy link
Contributor Author

CI started

@mbed-ci
Copy link

mbed-ci commented Dec 17, 2019

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 1
Build artifacts

@adbridge adbridge merged commit 0770798 into ARMmbed:master Dec 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BREAKING-CHANGE release-version: 6.0.0-alpha-1 First pre-release version of 6.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants