Overload selection issue with GeometryAttribute::GetValue
- Dominant language
- C++
- Stars
- 7.5k
- Forks
- 1.1k
- Avg merge
- 47m
- Merged PRs (30d)
- 1
Description
Please take a look at [this](https://github.com/vsautin/draco/commit/ea550837a36c5fb6fbe6203621202a15d3c3cfe4) 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 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
bool GetValue(AttributeValueIndex att_index, std::array *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](https://godbolt.org/z/Koh3cP). 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?
Contributor guide
Assessment
This issue has not been assessed yet.