The decimal types have no operator<=> with GCC and Clang if no earlier header includes <compare>
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 25/100
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/decimal
-
Difficulty 4/5 3-5 days Newbie friendliness 22/100
Maintainers usually reply within 1 day
-
comparetotal gives incorrect results for NaN operandsPossibly taken @ibmibmibm claimed this 1 day ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 25/100
Maintainers usually reply within 1 day
-
A comparison of a decimal and an integer gives incorrect resultsPossibly taken @ibmibmibm claimed this 1 day ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 22/100
Maintainers usually reply within 1 day
-
A comparison of two decimal types can use the type with fewer digitsPossibly taken @ibmibmibm claimed this 1 day ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 20/100
Maintainers usually reply within 1 day
-
sinh, cosh, tanh, expm1 and exp2 give incorrect results, and 0 or infinity for some finite resultsPossibly taken @ibmibmibm claimed this 7 days ago. Open
Difficulty 5/5 Over a week Newbie friendliness 10/100
Maintainers usually reply within 1 day
All issues in boostorg/decimal
Similar issues
-
agent:WSL code-review linux pri:medium refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
kind/enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
psi29a/d2decomped#691 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
CachyOS/packageinstaller#144 ·
Maintainers usually reply within 1 day
-
(S1 - Need confirmation)
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
CleverRaven/Cataclysm-DDA#89715 ·
Maintainers usually reply within 1 day