wesnoth / wesnoth

An open source, turn-based strategy game with a high fantasy theme.
https://www.wesnoth.org/
GNU General Public License v2.0
5.31k stars 995 forks source link

config's automatic conversion of an attribute to bool gives unexpected behavior #9009

Open Pentarctagon opened 1 week ago

Pentarctagon commented 1 week ago

When using the automatic conversion of a config attribute to a bool, such as with:

bool b = cfg["some_attribute"]

The variable b will always be false regardless of the attribute's actual value. This is due to calling operator int() in config_attribute_value.hpp instead of explicit operator bool(), which results in using the attribute_numeric_visitor which uses the default value of 0 for bool values instead of its actual value.

Potential solutions mentioned by celticminstrel from IRC:

Any fix for this issue should also include test cases added to the boost unit tests for this behavior as well.

gfgtdf commented 1 week ago

instead of removing both operators we could probably also make the operator int explicit too,