C++ spaceship operator `default` marked as deleted with `std::array` member

321 Views Asked by At

I am trying to understand why the spaceship operator for an std::array is marked as deleted when the std::array is a member, while the operator<=> itself is defined for std::array. I am using Apple Clang (XCode 14.1).

The following code does not compile

#include <array>
#include <compare>

struct test
{
    std::array<std::int64_t, 1> coords;
    auto operator<=>(const test&) const = default;
};

void test_f() {
    test c1{1}, c2{2};
    auto t1 = (c1 <= c2);
}

the error being

defaulted 'operator<=>' is implicitly deleted because there is no viable 
three-way comparison function for member 'coords'

However the code here compiles without issue:

void test_2() {
    std::array<std::int64_t, 1> coords{0};
    auto t1 = (coords <= coords);
}

and I was expecting the operator<=> for the struct test uses the definition of operator<=> for std::array when applied to this little struct.

clang versions (edit)

 % which clang
/usr/bin/clang

 % clang --version
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

and tried also with

 % clang --version
clang version 15.0.2                                                             
Target: arm64-apple-darwin21.6.0                                                 
Thread model: posix                                                              
InstalledDir: /Volumes/Data/program/clang+llvm-15.0.2-arm64-apple-darwin21.0/bin 

on macOS m1.

Compilation (edit)

The steps for reproducing are like this:

  1. download an official clang build and deflate the archive

  2. pull clang to PATH

    export PATH=/Volumes/Data/programs/clang+llvm-15.0.3-x86_64-apple-darwin/bin:$PATH
    
  3. make sure clang is trusted (open the folder containing clang w. Finder, right click, select open, and execute)

  4. run the following command line

    export SDKROOT=$(xcrun --show-sdk-path --sdk macosx)
    clang --version
    clang -std=c++20 -isysroot $SDKROOT/ test.cpp
    

    where test.cpp is the snippet above.

I have 100% error reproducibility with this and tested 2 different Xcode, 2 different architectures, and clang 14.0.0, 15.0.0, 15.0.1 and 15.0.3.

What am I doing wrong?

0

There are 0 best solutions below