考虑以下代码片段:
\n#include<array>\n#include<cstdint>\n\nconst std::array<int, 3> array{0, 1 , 2};\n\ntemplate<class string_type>\nauto parse(string_type&& name) {\n const auto s = std::uint8_t{array.size()};\n return s;\n}\nRun Code Online (Sandbox Code Playgroud)\n虽然它使用 gcc 9.3.0(Ubuntu 20.04 上的默认值)进行编译,但使用 gcc 11.2.0(从源代码构建)会失败,并显示以下错误消息:
\ntest2.cpp: In function \xe2\x80\x98auto parse(string_type&&)\xe2\x80\x99:\ntest2.cpp:8:47: error: no matching function for call to \xe2\x80\x98std::array<int, 3>::size(const std::array<int, 3>*)\xe2\x80\x99\n 8 | const auto s = std::uint8_t{array.size()};\n | ~~~~~~~~~~^~\nIn file included from test2.cpp:1:\n/opt/modules/install/gcc/11.2.0/include/c++/11.2.0/array:176:7: note: candidate: \xe2\x80\x98constexpr 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 …Run Code Online (Sandbox Code Playgroud)