Skip to content

Make sure that proper operator function of ESM:FIXED_STRING is used for char[N] argument

Adam Fandrejewski requested to merge Azdul/openmw:esm_name_template_fix into master

Fixes the problem #4826 (closed), which can be reproduced by running test_fixed_string unit test on Windows.

ESM:FIXED_STRING_BASE had two operator== functions, one intended for char[N] arguments:

template<size_t OTHER_SIZE> bool operator==(char const (&str)[OTHER_SIZE]) const

and one intended for const char* arguments:

bool operator==(const char* const str) const

Unfortunately first one will never be called on Microsoft compiler, because Microsoft compiler prefers non-template function over template one during overload resolution (§13.3.3/1 of C++ specification).

Second operator function assumes that char* is NULL terminated, which is not the case for char s[4] = {'a', 's', 'd', 'c'}; used in test_fixed_string, and test fails.

The fix changes second operator function to template function which checks during compilation if argument is really pointer to a char.

Tested on GCC (works as before) and Microsoft Visual Studio compiler (unit test no longer fails, and correct function is selected). I've added few more unit tests, to make sure that proper operator is also selected for const char s[4] = {'a', 's', 'd', 'c'}; argument.

Merge request reports