< => X86和ARM的操作员的行为不同
我有以下代码在
#include <array>
#include <iostream>
template <class T>
class A
{
public:
std::array<T,2> data_;
constexpr friend auto operator<=>(const A<T>& a, const A<T>& b)
{
return ( a.data_ <=> b.data_ );
}
};
int main()
{
using B = A<int>;
auto a = B{0,0};
auto b = B{1,1};
std::cout << std::boolalpha;
std::cout << (a.data_ <b.data_ );
std::cout << (a<b);
}
该代码在ARM Mac上与ARM Mac上的同一程序,与ARM Mac上的同一程序,与ARM Mac上的同一程序,
clang++ spacetest.cpp -o spaceship -std=c++20
给我以下错误,
spacetest.cpp:11:27: error: invalid operands to binary expression ('const std::array<int, 2>' and 'const std::array<int, 2>')
return ( a.data_ <=> b.data_ );
编译器版本是
clang++ -v
Homebrew clang version 13.0.0
Target: arm64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin
如此,我不知道我在这里做错了什么。感谢提示。
I have the following code which compiles correctly on godbolt:
#include <array>
#include <iostream>
template <class T>
class A
{
public:
std::array<T,2> data_;
constexpr friend auto operator<=>(const A<T>& a, const A<T>& b)
{
return ( a.data_ <=> b.data_ );
}
};
int main()
{
using B = A<int>;
auto a = B{0,0};
auto b = B{1,1};
std::cout << std::boolalpha;
std::cout << (a.data_ <b.data_ );
std::cout << (a<b);
}
The same program on Arm Mac, compiling with
clang++ spacetest.cpp -o spaceship -std=c++20
gives me the following error
spacetest.cpp:11:27: error: invalid operands to binary expression ('const std::array<int, 2>' and 'const std::array<int, 2>')
return ( a.data_ <=> b.data_ );
The compiler version is
clang++ -v
Homebrew clang version 13.0.0
Target: arm64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin
So, I dunno what I'm doing wrong here. Appreciate hints.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为@cpplearner的评论是他的权利。由于版本10.1,
&lt; =&gt;
运算符在libstdc ++中支持(请参阅表1.9此处 https://gcc.gnu.org/onlinedocs/libstdc++++++++++++s.html#status.iso.iso.iso.2020 )。 CompilereXplorer使用v8.2工具链用于ARM,因此尚未支持。对于x64,它使用v11.2,因此受支持。您可以通过在命令行上添加
-V
编译器标志来检查版本。I think @cpplearner his right with his comment. The
<=>
operator is supported in libstdc++ since version 10.1 (see table 1.9 here https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2020). The compilerexplorer uses the v8.2 toolchain for arm, so it's not yet supported. For x64, it uses v11.2, so it is supported.You can check for the version by adding the
-v
compiler flag on the command line.