Overload selection issue with GeometryAttribute::GetValue
Please take a look at this simple unit test for GeometryAttribute::GetValue(). (I put it into point_attribute_test.cc, just did not want to add new file to the build). The essential part of it is below:
draco::AttributeValueIndex index{0};
std::array<float, 4> arr;
draco::GeometryAttribute ga;
bool status = ga.GetValue(index, &arr);
This code compiles fine with MSVC, but it fails to compile with other compilers I tried:
- Clang 10 on Windows (the one coming with Visual Studio 2019)
- Clang 9 and Clang 10 on Linux (Ubuntu 18.04)
- GCC 8.4 ang GCC 9.3 on Linux (Ubuntu 18.04).
The error messages are like these:
point_attribute_test.cc(132,8): error : cannot initialize a variable of type 'bool' with an rvalue of type 'void'
bool status = ga.GetValue(index, &arr);
or
point_attribute_test.cc:132:40: error: void value not ignored as it ought to be
bool status = ga.GetValue(index, &arr);
The reason seems to be that for the code above this overload of GeometryAttribute::GetValue() gets selected:
void GetValue(AttributeValueIndex att_index, void *out_data) const;
instead of the templated one I would expect:
template <typename T, int att_components_t>
bool GetValue(AttributeValueIndex att_index, std::array<T, att_components_t> *out) const;
As far as I understand, this happens because the std::array template uses std::size_t for its second argument, while GetValue() definition uses int for the size argument of std::array. MSVC seems to be forgiving about this while other compilers are not. I could not find particular clauses in the language standard that specify what should be the correct behavior (it must be somewhere there though).
Not sure if this is an issue or maybe I'm just using the method incorrectly?