A C++ implementation that detects undefined behavior?

后端 未结 10 1392
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 14:13

A huge number of operations in C++ result in undefined behavior, where the spec is completely mute about what the program\'s behavior ought to be and allows for anything to

10条回答
  •  广开言路
    2020-11-27 14:41

    Unfortunately I'm not aware of any such tool. Typically UB is defined as such precisely because it would be hard or impossible for a compiler to diagnose it in all cases.

    In fact your best tool is probably compiler warnings: They often warn about UB type items (for example, non-virtual destructor in base classes, abusing the strict-aliasing rules, etc).

    Code review can also help catch cases where UB is relied upon.

    Then you have to rely on valgrind to capture the remaining cases.

提交回复
热议问题