Consider the following snippet of code:
#include<array>
#include<cstdint>
const std::array<int, 3> array{0, 1 , 2};
template<class string_type>
auto parse(string_type&& name) {
const auto s = std::uint8_t{array.size()};
return s;
}
While it compiles using gcc 9.3.0 (the default on Ubuntu 20.04), it fails with gcc 11.2.0 (built from sources) with the following error message:
test2.cpp: In function ‘auto parse(string_type&&)’:
test2.cpp:8:47: error: no matching function for call to ‘std::array<int, 3>::size(const std::array<int, 3>*)’
8 | const auto s = std::uint8_t{array.size()};
| ~~~~~~~~~~^~
In file included from test2.cpp:1:
/opt/modules/install/gcc/11.2.0/include/c++/11.2.0/array:176:7: note: candidate: ‘constexpr std::array<_Tp, _Nm>::size_type std::array<_Tp, _Nm>::size() const [with _Tp = int; long unsigned int _Nm = 3; std::array<_Tp, _Nm>::size_type = long unsigned int]’
176 | size() const noexcept { return _Nm; }
| ^~~~
/opt/modules/install/gcc/11.2.0/include/c++/11.2.0/array:176:7: note: candidate expects 0 arguments, 1 provided
Besides the fact that it does not make much sense, I can't find where is the error, can you help me?
‘auto parse(string_type&&)’:-- rvalue string is actually return value type, gcc somehow treated it as parameter. and inarray.sizegcc treated implicitthisas explicit parameter.