I'm currently playing around with constexpr arrays, and i noticed that i can't get the following (valid) code to compile under MSVC 19.15.26726 with /std:c++17 or /std:c++latest:
#include <array>
using array_type = std::array<unsigned int, 3>;
using iterator_type = array_type::const_iterator;
constexpr array_type arr{ { 1,2,3 } };
constexpr iterator_type getIteratorBefore(iterator_type it) {
return std::prev(it);
}
constexpr iterator_type test = getIteratorBefore(arr.end());
Ignoring all the highlighting errors and the error that says std::array is ambigous (seems to conflict with some weird array() function in the same file) that I'm getting from IntelliSense, I get the following compiler errors in the last line:
error C4146: unary minus operator applied to unsigned type, result still unsigned
error C4308: negative integral constant converted to unsigned type
warning C4307: '+': integral constant overflow
It compiles fine in compiler explorer under gcc (x86-64 gcc (trunk)) and MSVC (x86-64 edit: MSVC Pre 2018 with /std:c++17 works) (didn't test the others).
I'm seriously out of ideas. The same code compiles when i put it in a main method, so it seems to be an issue with the constexpr scope.
/std:c++latestand the code compile andtestpoints to 3. The two errors you show come up as warnings for me but the code does compile.