mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #5485 from pan-/non-copyable-warning
Platform: Allow copy of non copyable objectspull/5358/merge
commit
4198695fab
|
@ -16,6 +16,11 @@
|
||||||
#ifndef MBED_NONCOPYABLE_H_
|
#ifndef MBED_NONCOPYABLE_H_
|
||||||
#define MBED_NONCOPYABLE_H_
|
#define MBED_NONCOPYABLE_H_
|
||||||
|
|
||||||
|
#if (!defined(MBED_DEBUG) && (MBED_CONF_PLATFORM_FORCE_NON_COPYABLE_ERROR == 0))
|
||||||
|
#include "mbed_toolchain.h"
|
||||||
|
#include "mbed_debug.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,6 +141,10 @@ namespace mbed {
|
||||||
* // empty base optimization can be applied B and C does not refer to the same
|
* // empty base optimization can be applied B and C does not refer to the same
|
||||||
* // kind of A. sizeof(C) == sizeof(B) == sizeof(int).
|
* // kind of A. sizeof(C) == sizeof(B) == sizeof(int).
|
||||||
* @endcode
|
* @endcode
|
||||||
|
*
|
||||||
|
* @note Compile time errors are disabled if the develop or the release profile
|
||||||
|
* is used. To override this behavior and force compile time errors in all profile
|
||||||
|
* set the configuration parameter "platform.force-non-copyable-error" to true.
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class NonCopyable {
|
class NonCopyable {
|
||||||
|
@ -149,6 +158,39 @@ protected:
|
||||||
*/
|
*/
|
||||||
~NonCopyable() { }
|
~NonCopyable() { }
|
||||||
|
|
||||||
|
#if (!defined(MBED_DEBUG) && (MBED_CONF_PLATFORM_FORCE_NON_COPYABLE_ERROR == 0))
|
||||||
|
/**
|
||||||
|
* NonCopyable copy constructor.
|
||||||
|
*
|
||||||
|
* A compile time warning is issued when this function is used and a runtime
|
||||||
|
* warning is printed when the copy construction of the non copyable happens.
|
||||||
|
*
|
||||||
|
* If you see this warning, your code is probably doing something unspecified.
|
||||||
|
* Copy of non copyable resources can lead to resource leak and random error.
|
||||||
|
*/
|
||||||
|
MBED_DEPRECATED("Invalid copy construction of a NonCopyable resource.")
|
||||||
|
NonCopyable(const NonCopyable&)
|
||||||
|
{
|
||||||
|
debug("Invalid copy construction of a NonCopyable resource: %s\r\n", MBED_PRETTY_FUNCTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NonCopyable copy assignment operator.
|
||||||
|
*
|
||||||
|
* A compile time warning is issued when this function is used and a runtime
|
||||||
|
* warning is printed when the copy construction of the non copyable happens.
|
||||||
|
*
|
||||||
|
* If you see this warning, your code is probably doing something unspecified.
|
||||||
|
* Copy of non copyable resources can lead to resource leak and random error.
|
||||||
|
*/
|
||||||
|
MBED_DEPRECATED("Invalid copy assignment of a NonCopyable resource.")
|
||||||
|
NonCopyable& operator=(const NonCopyable&)
|
||||||
|
{
|
||||||
|
debug("Invalid copy assignment of a NonCopyable resource: %s\r\n", MBED_PRETTY_FUNCTION);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Declare copy constructor as private, any attempt to copy construct
|
* Declare copy constructor as private, any attempt to copy construct
|
||||||
|
@ -161,6 +203,7 @@ private:
|
||||||
* a NonCopyable will fail at compile time.
|
* a NonCopyable will fail at compile time.
|
||||||
*/
|
*/
|
||||||
NonCopyable& operator=(const NonCopyable&);
|
NonCopyable& operator=(const NonCopyable&);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mbed
|
} // namespace mbed
|
||||||
|
|
|
@ -19,6 +19,11 @@
|
||||||
"default-serial-baud-rate": {
|
"default-serial-baud-rate": {
|
||||||
"help": "Default baud rate for a Serial or RawSerial instance (if not specified in the constructor)",
|
"help": "Default baud rate for a Serial or RawSerial instance (if not specified in the constructor)",
|
||||||
"value": 9600
|
"value": 9600
|
||||||
|
},
|
||||||
|
|
||||||
|
"force-non-copyable-error": {
|
||||||
|
"help": "Force compile time error when a NonCopyable object is copied",
|
||||||
|
"value": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"target_overrides": {
|
"target_overrides": {
|
||||||
|
|
|
@ -330,6 +330,20 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Macro expanding to a string literal of the enclosing function name.
|
||||||
|
*
|
||||||
|
* The string returned takes into account language specificity and yield human
|
||||||
|
* readable content.
|
||||||
|
*
|
||||||
|
* As an example, if the macro is used within a C++ function then the string
|
||||||
|
* literal containing the function name will contain the complete signature of
|
||||||
|
* the function - including template parameters - and namespace qualifications.
|
||||||
|
*/
|
||||||
|
#ifndef MBED_PRETTY_FUNCTION
|
||||||
|
#define MBED_PRETTY_FUNCTION __PRETTY_FUNCTION__
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef MBED_PRINTF
|
#ifndef MBED_PRINTF
|
||||||
#if defined(__GNUC__) || defined(__CC_ARM)
|
#if defined(__GNUC__) || defined(__CC_ARM)
|
||||||
#define MBED_PRINTF(format_idx, first_param_idx) __attribute__ ((__format__(__printf__, format_idx, first_param_idx)))
|
#define MBED_PRINTF(format_idx, first_param_idx) __attribute__ ((__format__(__printf__, format_idx, first_param_idx)))
|
||||||
|
|
Loading…
Reference in New Issue