Skip to content

feat: enforce callback signatures with C++ Concepts (#1746) - #1762

Open
dave-365 wants to merge 4 commits into
nodejs:mainfrom
dave-365:feat/cpp20-concepts
Open

dave-365 wants to merge 4 commits into
nodejs:mainfrom
dave-365:feat/cpp20-concepts

Conversation

@dave-365

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

Copy link
Copy Markdown

Fixes #1746

Overview

When passing mismatched callback or finalizer signatures to methods such as Function::New, PropertyDescriptor::Accessor, Object::AddFinalizer, or ThreadSafeFunction::New, unconstrained templates would fail deep inside internal wrappers (such as details::CallbackData in napi-inl.h). This produced lengthy, cryptic template instantiation errors that were difficult to decipher.

This PR adopts C++20 Concepts () to enforce callable and finalizer signatures at the call site at compile time, providing immediate and readable compiler diagnostics while maintaining 100% backward compatibility for pre-C++20 builds.

@codecov-commenter

codecov-commenter commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.64%. Comparing base (25c6b21) to head (7c03fa3).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1762      +/-   ##
==========================================
- Coverage   63.68%   63.64%   -0.04%     
==========================================
  Files           3        3              
  Lines        2065     2071       +6     
  Branches      731      738       +7     
==========================================
+ Hits         1315     1318       +3     
+ Misses        162      161       -1     
- Partials      588      592       +4     

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

@KevinEady run local everything works fine you feel free to approve workflow.

@KevinEady

Copy link
Copy Markdown
Contributor

Hi @dave-365 ,

Looks like linter failed. Can you also rebase to main? Thanks :)

@dave-365
dave-365 force-pushed the feat/cpp20-concepts branch from a6989c4 to 386399c Compare November 8, 2026 06:26
@dave-365

dave-365 commented Nov 8, 2026

Copy link
Copy Markdown
Author

Hi @dave-365 ,

Looks like linter failed. Can you also rebase to main? Thanks :)

@KevinEady Both was done. can you check now.

@dave-365

dave-365 commented Nov 9, 2026

Copy link
Copy Markdown
Author

@KevinEady can you proceed workflow run.

@dave-365

Copy link
Copy Markdown
Author

@KevinEady just friendly reminder just it's waiting for apprval workflow checks.

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

Co-authored-by: Chengzhong Wu <legendecas@gmail.com>

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

Projects

Status: Need Triage

Development

Successfully merging this pull request may close these issues.

Enforce callback signatures with C++ Concepts

4 participants