Skip to content

feat: adopt C++20 defaulted comparisons and spaceship operator - #1761

Open
dave-365 wants to merge 1 commit into
nodejs:mainfrom
dave-365:feat/cpp20-comparisons
Open

dave-365 wants to merge 1 commit into
nodejs:mainfrom
dave-365:feat/cpp20-comparisons

Conversation

@dave-365

@dave-365 dave-365 commented Nov 4, 2026

Copy link
Copy Markdown

Fixes #1748

Summary of Changes:

  • Leverage C++20 defaulted comparisons (operator== and <=>) when compiling under C++20 or later.
  • Remove redundant hand-written operator!= implementations in C++20 mode for Value, Reference<T>, Object::iterator, Object::const_iterator, and Maybe<T> as the compiler synthesizes them automatically from operator==.
  • Adopt = default equality and three-way comparison (<=>) for BasicEnv.
  • Add spaceship operator (<=>) for Maybe<T> using std::compare_three_way_result_t<T> to support relational ordering when T supports comparison.
  • Preserve full backward compatibility for C++14/C++17 compilers under #if !defined(NAPI_HAS_CPP20_COMPARISONS).
  • Add binding_cpp20 target and unit tests covering C++20 comparison behavior.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 63.75%. Comparing base (25c6b21) to head (0cce782).

Files with missing lines Patch % Lines
napi.h 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1761      +/-   ##
==========================================
+ Coverage   63.68%   63.75%   +0.07%     
==========================================
  Files           3        3              
  Lines        2065     2072       +7     
  Branches      731      737       +6     
==========================================
+ Hits         1315     1321       +6     
  Misses        162      162              
- Partials      588      589       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Need Triage

Development

Successfully merging this pull request may close these issues.

Adopt C++20 defaulted comparisons (operator== / <=>)

2 participants