The decimal types have no operator<=> with GCC and Clang if no earlier header includes <compare>

Open
#1,566 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@ibmibmibm is already working on this.

Since Nov 22, 2026.

  • #1567 by @ibmibmibm — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
25/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
cpp
Domain
backend

Research direction

The header check lives in config.hpp: it includes <compare> only when __cpp_lib_three_way_comparison is already defined, so the fix is to include <compare> first under C++20 and then test the macro. Compile the reproduction with boost/decimal.hpp as the only include and confirm a <=> b builds on GCC and Clang. Done when it compiles and returns 0 without -include compare. Linked PR #1567 is already open, so check it before starting.

Written by the indexing model from the issue text.

Description

Problem

config.hpp includes <compare> only if it finds the macro __cpp_lib_three_way_comparison. But <compare> or <version> defines this macro. If no earlier header includes one of them, config.hpp does not define BOOST_DECIMAL_HAS_SPACESHIP_OPERATOR, and the decimal types have no operator<=> in C++20.

Reproduction

#include <boost/decimal.hpp>

int main()
{
    const boost::decimal::decimal64_t a {1};
    const boost::decimal::decimal64_t b {2};
    return (a <=> b) < 0 ? 0 : 1;
}

Result on develop (215bbf025), GCC 16.2.1, x86-64 Linux, C++20. Clang 23.1.5 with libstdc++ gives the same error.

r11.cpp:7:15: error: no match for 'operator<=>' (operand types are 'const boost::decimal::decimal64_t' and 'const boost::decimal::decimal64_t')

The program compiles with -include compare.

Expected result

The program compiles and returns 0 with boost/decimal.hpp as the only include.

Proposed fix

In C++20 and later, include <compare> first, then test __cpp_lib_three_way_comparison.

Reference

  • #1490 (Relook Fundamental Optimization of Comparisons)
Dominant language
C++
Stars
67
Forks
16
Avg merge
1d 15h
Merged PRs (30d)
12

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/decimal

All issues in boostorg/decimal

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.