Skip to content

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

Open
dave-365 wants to merge 11 commits into
nodejs:mainfrom
dave-365:feat/cpp20-comparisons
Open

dave-365 wants to merge 11 commits into
nodejs:mainfrom
dave-365:feat/cpp20-comparisons

Conversation

@dave-365

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

Copy link
Copy Markdown
Contributor

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

codecov-commenter commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.63%. Comparing base (209151e) to head (06b358a).

Files with missing lines Patch % Lines
napi.h 60.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1761      +/-   ##
==========================================
- Coverage   63.64%   63.63%   -0.01%     
==========================================
  Files           3        3              
  Lines        2071     2076       +5     
  Branches      738      742       +4     
==========================================
+ Hits         1318     1321       +3     
  Misses        161      161              
- Partials      592      594       +2     

☔ 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.

@dave-365

dave-365 commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

@KevinEady failed test case updated and checked in npm run pretest local working fine.

@dave-365

dave-365 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@KevinEady all checks have been done. Can you proceed further. Thank you.

@dave-365

Copy link
Copy Markdown
Contributor Author

@KevinEady this one too all checks was done if no error can you proceed for futher merge.

Comment thread napi.h Resolved
__cpp_lib_three_way_comparison should be checked after #include <version> https://en.cppreference.com/cpp/header/version:

Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
@dave-365
dave-365 requested a review from legendecas November 14, 2026 11:22
Comment thread napi.h Resolved
Comment thread napi.h Resolved
@dave-365

Copy link
Copy Markdown
Contributor Author

@legendecas lint error style fix applied kindly approve the workflow and do the further process.

@dave-365

dave-365 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@legendecas this issues also SemVer Major label need to update, and can you proceed further.

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== / <=>)

3 participants