< => X86和ARM的操作员的行为不同

发布于 2025-01-28 01:47:53 字数 1098 浏览 2 评论 0原文

我有以下代码在

#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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

错々过的事 2025-02-04 01:47:53

我认为@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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文