Skip to content

Remove const qualifier from object that can be modified

Jeff Trull requested to merge jaafar/graph-tool:UB-constness into master

Modifying an object declared const is technically undefined behavior, and compilers are entitled to do as they like with such code. The most likely result - in the event of some future optimizer - would be elimination of the code performing the modification, although it could theoretically be anything.

Given that ConstantPropertyMap defines an assignment operator already, simply changing the underlying data member to non-const (while making it private) seems to achieve the same result as the current code, while avoiding UB.

Merge request reports