LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 51052 - std::tuple still missing C++20 three-way spaceship operator<=>
Summary: std::tuple still missing C++20 three-way spaceship operator<=>
Status: NEW
Alias: None
Product: libc++
Classification: Unclassified
Component: Standards Issues (show other bugs)
Version: unspecified
Hardware: PC Linux
: P enhancement
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-07-11 01:23 PDT by Kent Ross
Modified: 2021-08-24 09:00 PDT (History)
6 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kent Ross 2021-07-11 01:23:41 PDT
In the C++20 standard, std::tuple is meant to have its old {<,<=,==,!=,>=,>} comparison operators deprecated in favor of the three-way comparison spaceship operator, <=>. In the very latest iteration of libc++ (currently 1:13~++20210710113609+8cf7ddbdd4e5-1~exp1~20210710094359.522), this has yet to be the case.

Example:

clang-13 -xc++ -std=c++20 -stdlib=libstdc++ -lstdc++ <(cat <<EOF
#include <tuple>
int main(int, char**) {
  int a = 1, b = 1;
  auto compared = std::tie(a) <=> std::tie(b);
  return compared < 0;
}
EOF
) && ./a.out && echo "okay"

The above command prints "okay", because libstdc++ supports <=> comparison between std::tuples.

clang-13 -xc++ -std=c++20 -stdlib=libc++ -lc++ <(cat <<EOF
#include <tuple>
int main(int, char**) {
  int a = 1, b = 1;
  auto compared = std::tie(a) <=> std::tie(b);
  return compared < 0;
}
EOF
) && ./a.out && echo "okay"

The above command fails to compile the program, with the following error message:

error: invalid operands to binary expression ('tuple<int &>' and 'tuple<int &>')
  auto compared = std::tie(a) <=> std::tie(b);
                  ~~~~~~~~~~~ ^   ~~~~~~~~~~~

Further investigation reveals that the <tuple> header contains no definitions for operator<=>, and my efforts to locate a TODO for this feature in the libc++ effort have come up fruitless.
Comment 1 Kent Ross 2021-08-24 09:00:36 PDT
This is an existing subproject of a slowly-ongoing but little-documented effort. There is now a tracking page, and this is almost ready to ship: https://libcxx.llvm.org/Status/Spaceship.html