16
16
#ifndef MBED_NONCOPYABLE_H_
17
17
#define MBED_NONCOPYABLE_H_
18
18
19
+ #if (!defined(MBED_DEBUG) && (MBED_CONF_PLATFORM_FORCE_NON_COPYABLE_ERROR == 0))
20
+ #include " mbed_toolchain.h"
21
+ #include " mbed_debug.h"
22
+ #endif
23
+
19
24
namespace mbed {
20
25
21
26
/* *
@@ -136,6 +141,10 @@ namespace mbed {
136
141
* // empty base optimization can be applied B and C does not refer to the same
137
142
* // kind of A. sizeof(C) == sizeof(B) == sizeof(int).
138
143
* @endcode
144
+ *
145
+ * @note Compile time errors are disabled if the develop or the release profile
146
+ * is used. To override this behavior and force compile time errors in all profile
147
+ * set the configuration parameter "platform.force-non-copyable-error" to true.
139
148
*/
140
149
template <typename T>
141
150
class NonCopyable {
@@ -149,6 +158,39 @@ class NonCopyable {
149
158
*/
150
159
~NonCopyable () { }
151
160
161
+ #if (!defined(MBED_DEBUG) && (MBED_CONF_PLATFORM_FORCE_NON_COPYABLE_ERROR == 0))
162
+ /* *
163
+ * NonCopyable copy constructor.
164
+ *
165
+ * A compile time warning is issued when this function is used and a runtime
166
+ * warning is printed when the copy construction of the non copyable happens.
167
+ *
168
+ * If you see this warning, your code is probably doing something unspecified.
169
+ * Copy of non copyable resources can lead to resource leak and random error.
170
+ */
171
+ MBED_DEPRECATED (" Invalid copy construction of a NonCopyable resource." )
172
+ NonCopyable(const NonCopyable&)
173
+ {
174
+ debug (" Invalid copy construction of a NonCopyable resource: %s\r\n " , MBED_PRETTY_FUNCTION);
175
+ }
176
+
177
+ /* *
178
+ * NonCopyable copy assignment operator.
179
+ *
180
+ * A compile time warning is issued when this function is used and a runtime
181
+ * warning is printed when the copy construction of the non copyable happens.
182
+ *
183
+ * If you see this warning, your code is probably doing something unspecified.
184
+ * Copy of non copyable resources can lead to resource leak and random error.
185
+ */
186
+ MBED_DEPRECATED (" Invalid copy assignment of a NonCopyable resource." )
187
+ NonCopyable& operator=(const NonCopyable&)
188
+ {
189
+ debug (" Invalid copy assignment of a NonCopyable resource: %s\r\n " , MBED_PRETTY_FUNCTION);
190
+ return *this ;
191
+ }
192
+
193
+ #else
152
194
private:
153
195
/* *
154
196
* Declare copy constructor as private, any attempt to copy construct
@@ -161,6 +203,7 @@ class NonCopyable {
161
203
* a NonCopyable will fail at compile time.
162
204
*/
163
205
NonCopyable& operator =(const NonCopyable&);
206
+ #endif
164
207
};
165
208
166
209
} // namespace mbed
0 commit comments