Skip to content

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

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

dave-365 wants to merge 1 commit 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

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.69%. Comparing base (25c6b21) to head (4dcfcc5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1762      +/-   ##
==========================================
+ Coverage   63.68%   63.69%   +0.01%     
==========================================
  Files           3        3              
  Lines        2065     2066       +1     
  Branches      731      732       +1     
==========================================
+ Hits         1315     1316       +1     
  Misses        162      162              
  Partials      588      588              

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

Enforce callback signatures with C++ Concepts

2 participants