Commit ac746100 authored by Jeff Trull's avatar Jeff Trull

Remove const qualifier from object that can be modified

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.
parent 6f8ba179
......@@ -562,7 +562,7 @@ private:
value_type _default;
};
// the following is a property map which always returns a constant value
// the following is a property map which always returns the same value
template <class Value, class Key>
class ConstantPropertyMap
: public boost::put_get_helper<Value, ConstantPropertyMap<Value,Key>>
......@@ -581,11 +581,12 @@ public:
ConstantPropertyMap& operator=(const ConstantPropertyMap& other)
{
const_cast<value_type&>(c) = other.c;
c = other.c;
return *this;
}
const value_type c;
private:
value_type c;
};
template <class Value, class Key>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment