Curiously Recurring C++ Bugs

Timon Gehr timon.gehr at gmx.ch
Thu Jul 11 22:39:27 UTC 2024


On 7/11/24 22:36, Walter Bright wrote:
> https://www.youtube.com/watch?v=lkgszkPnV8g
> 
> This is a great talk. In my first pass, D doesn't suffer from any of them.
> 
> Anyone want to verify?

Well, the situation in D is overall much better, but I wouldn't say it 
does not suffer from any of them.


- std::vector::operator[]:
   D code still suffers from unrecoverable range errors that would crash 
the website, it's just not a memory safety issue unless you pass badly 
designed compiler flags like `-release`.


- std::map::operator[]:
   Not a problem in D.


- get_default():
   Potential for lifetime error fixed with DIP1000.
   Still potentially a performance problem in D without DIP1040.


- volatile:
   Not clear, but I guess `volatile` is less popular nowadays.
   https://dlang.org/phobos/core_volatile.html
   D also does not have a full `shared` story so far.


- shared_ptr thread-safe:
   Potentially fixed because D has transitive `shared`. But again, 
`shared` is unfinished. Or use GC.


- shared_ptr bonus bug:
   Simple pattern like the one on the slide seem superficially fixable 
with DIP1000, but in general in D it is not possible to make smart 
pointer dereferencing safe. Can use GC though.


- lock bug:
   That syntax would not lock until the end of the scope in D either, 
but for different reasons. But there is no reason to expect it would 
work, so I guess we can consider this fixed in D.


I guess the lessons are:

- D also does not have static typing to rule out range errors.
- D also does not have memory safety for general allocator-backed 
container types.
- remove `-release`
- implement DIP1040.
- finalize `shared`.


More information about the Digitalmars-d mailing list