-
Notifications
You must be signed in to change notification settings - Fork 3k
Introduce mbed::NonCopyable traits #4594
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
Conversation
The NonCopyable template class avoid autogeneration of copy assignement and copy construction function for classes inheriting from it.
…le, FileSystemLike, LocalFileHandle, LocalFileSystem and PlatformMutex as non copyable. This avoid unwanted copy of these type which is a programming error.
…tor by a NonCopyable tag. The class concerned by this change are: ATCmdParser, CallChain, FileBase and Stream.
The types marked are: Mail, MemoryPool, Mutex, Queue, RtosTimer and Semaphore.
… in favor of the NonCopyable traits.
…or by NonCopyable traits. Modified classes are: BusIn, BusOut, BusInOut and InterruptManager.
… traits. Classes changed: CAN, Ethernet, FlashIAP, I2C, InterruptIn, LowPowerTicker, LowPowerTimeout, LowPowerTimer, RawSerial, Serial, SerialBase, SPI, SPISlave, Ticker, Timeout, Timer, TimerEvent and UARTSerial.
The jenkins CI fails
|
The CI failure is due to a programming error in the ST ble shield library: a Timeout object was incorrectly copied. Detecting this type of programming errors at compile time is the main motivation behind this PR. I have submitted a fix: ARMmbed/ble-x-nucleo-idb0xa1#27 |
Since the issue is detected by mbed-os-cliapp, I've also submitted a PR to update the ST BlueNRG library: https://github.com/ARMmbed/mbed-os-cliapp/pull/283 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
Excellent documentation and I find it enjoyable that we already found a bug XD
@0xc0170 the BLUENRG library has been updated in mbed-os cliapp, may you relaunch the tests ? |
restarted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
/morph test |
Result: SUCCESSYour command has finished executing! Here's what you wrote!
OutputAll builds and test passed! |
Description
The
NonCopyable
template class disable auto generation of copy assignment operator and copy constructor for classes inheriting from it.It avoid the private declaration of the copy assignment operator and copy constructor in favor of an explicit element in the base class list.
It is a good practice to tag non value type as
NonCopyable
, because it inform of invalid copy operation at compile time.As an example consider the following code:
There is a bug in this function, it returns a temporary value which will be
byte copied into
foo
then destroyed. Unfortunately, internally the Foo classmanage a pointer to a
Resource
object. This pointer will be released when thetemporary is destroyed and
foo
will manage a pointer to an already releasedResource
.If the class
Foo
is marked asNonCopyable
then it is not possible to write function with the signatureFoo get_foo();
because an error will be generated at compile time.The extensive documentation as well as the implementation details can be found in the NonCopyable header.
Classes in
rtos
,platform
,event
anddriver
have been either fixed or updated to take advantage of this new traits.Classes in
features
have not been touched.Status
READY
Todos