Strict mode for C++ |
The basic options for memory safety are garbage collection, reference counting, and static analysis. Garbage collection is a bad fit to C++. C++ destructor semantics are not compatible with garbage collection driven finalization Safe C++ from Xerox PARC tried this approach. Using Hans Boehm's conservative garbage collector, it worked, but never achieved much use.
Reference counting has a good track record with C++, in the form of "smart pointers". If better integrated with the language, it can be made safe. That is the essence of this proposal.
The novel feature of this proposal is the introduction of "temporary pointers", pointers which cannot outlive the object to which they point. Such pointers need no reference counts. This leads to a simple way of eliminating most reference count overhead within loops.
Now that the community has considerable experience with collections and iterators, it's become clear that collections deserve a more basic place in the language. So do iterators. STL collections are at least as useful as C's built-in arrays, and deserve comparable status in the language. Iterators should not be viewed as pointers, but as first-class constructs in their own right.
[elli93a] John R. Ellis and David L. Detlefs. Safe, efficient garbage collection for C++. Technical report, Xerox PARC, Palo Alto, CA, 1993.
July 2, 2001