简体   繁体   English

Apple 的 clang 不能将 <=> 与 std::tuple 一起使用

[英]Apple's clang can't use <=> with std::tuple

The following compiles fine with GCC and clang on on godbolt , but on my MacBook, in Xcode 14 it dies:以下代码在 GCC 和godbolt上编译得很好,但在我的 MacBook 上,在 Xcode 14 中它死了:

#include <iostream>
#include <compare>
#include <tuple>

using std::cout; using std::tuple; using std::endl;

int main() {
    tuple<float, float> tuplee = {1.0,2.0};
    tuple<float, float> tuploo = {3.0,4.0};
    cout << (tuplee < tuploo) << endl;
    auto res = (tuplee <=> tuploo);
    cout << (res < 0) << endl;
    return 0;
}

The error is:错误是:

invalid operands to binary expression ('std::tuple<float, float>' and 'std::tuple<float, float>')二进制表达式的无效操作数('std::tuple<float, float>' 和 'std::tuple<float, float>')

It points to the <=> on the tuples.它指向元组上的<=> Do you think it's a bug in Apple's clang, or am I missing something?你认为这是 Apple 的 clang 中的错误,还是我遗漏了什么?

Command line on my MacBook:我的 MacBook 上的命令行:

% clang++ --version          
Apple clang version 14.0.0 (clang-1400.0.29.102)
Target: x86_64-apple-darwin22.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
% clang++ -std=c++2b main.cpp
main.cpp:11:21: error: invalid operands to binary expression ('tuple<float, float>' and 'tuple<float, float>')
    cout << (tuplee <=> tuploo) << endl;
             ~~~~~~ ^   ~~~~~~
1 error generated.

I think it is a bug.我认为这是一个错误。 The bug was fixed in llvm ( relevant change ).该错误已在 llvm 中修复( 相关更改)。 But by checking the tuple header in Macos SDK, one can find apple do not implement <=> for tuple.但是通过检查 Macos SDK 中的元组头,可以发现苹果没有为元组实现 <=> 。

The bug also affects arm64 variants of Macos.该错误还影响 Macos 的 arm64 变体。 Clang version on my mac:我的 Mac 上的 Clang 版本:

➜  test clang --version                                  
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin22.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

PS.附言。 Homebrew llvm@14 compiles fine.自制 llvm@14 编译正常。 Just do not use apple clang只是不要使用 apple clang

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM