CARVIEW |
Select Language
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 24 Jul 2025 19:15:55 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Last-Modified: Tue, 28 Dec 2021 02:04:14 GMT
Content-Encoding: gzip
Secrets of Boost Revealed: Checked Delet - C++ Articles




Section I: What is the purpose?
The checked delete idiom adds a compile-time safety check against deleting incomplete classes. The C++ Standard mandates that a pointer to an incomplete class may be deleted, so long as the class has a trivial desctructor and does not overload operator delete. Deleting pointers to classes with non-trivial destructors, or classes that overload operator delete results in undefined behavior.
Section II: Problematic Code Example
Consider the following:
Most compilers generate a warning when this occurs, however some compilers have been known not to catch these errors. This is what the checked delete idiom is designed to remedy.
Section III: Line-By-Line Evaluation
Boost's implementation of the checked delete idiom consists of two function templates and two class templates.
While the bodies of the code look very similar, one set is used to check
Warning - The following contains opinions that cannot be cited to any documentation from boost.
Lines 1-6
Lines 8-16
Lines 19-34:
The line-by-line for checked_array_delete is essentially the same as above.
- Articles
- Secrets of Boost Revealed: Checked Delet
Published by closed account 3hM2Nwbp
Jun 17, 2011 (last update: Jun 17, 2011)
Secrets of Boost Revealed: Checked Delete
Score: 3.2/5 (22 votes)





Secrets of Boost Revealed
Boost C++ Libraries ( https://www.boost.org )
Topic / Idiom: Checked Delete
Contributor(s): Peter Dimov, Daniel Frey, Howard Hinnant
Boost Reference File(s): https://www.boost.org/doc/libs/1_46_1/boost/checked_delete.hpp
Note - This document may contain errors, if you spot one (or a dozen of them), let me know please.
Boost C++ Libraries ( https://www.boost.org )
Topic / Idiom: Checked Delete
Contributor(s): Peter Dimov, Daniel Frey, Howard Hinnant
Boost Reference File(s): https://www.boost.org/doc/libs/1_46_1/boost/checked_delete.hpp
Note - This document may contain errors, if you spot one (or a dozen of them), let me know please.
Section I: What is the purpose?
The checked delete idiom adds a compile-time safety check against deleting incomplete classes. The C++ Standard mandates that a pointer to an incomplete class may be deleted, so long as the class has a trivial desctructor and does not overload operator delete. Deleting pointers to classes with non-trivial destructors, or classes that overload operator delete results in undefined behavior.
Section II: Problematic Code Example
Consider the following:
|
|
Most compilers generate a warning when this occurs, however some compilers have been known not to catch these errors. This is what the checked delete idiom is designed to remedy.
Section III: Line-By-Line Evaluation
The original source is listed at the top of this article.
The following code has been stripped of comments and preprocessor directives.
The following code has been stripped of comments and preprocessor directives.
Boost's implementation of the checked delete idiom consists of two function templates and two class templates.
|
|
While the bodies of the code look very similar, one set is used to check
operator delete
and the other is used to check operator delete[]
.Warning - The following contains opinions that cannot be cited to any documentation from boost.
Lines 1-6
|
|
Lines 8-16
|
|
Lines 19-34:
The line-by-line for checked_array_delete is essentially the same as above.
Home page | Privacy policy
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.3
Spotted an error? contact us
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.3
Spotted an error? contact us