[cxx] Request for C++ Style Exception: std::function for Swift/C++ Interop

80 views
Skip to first unread message

Asami Doi

unread,
Feb 19, 2026, 12:43:46 PMFeb 19
to c...@chromium.org, Rohit Rao, Sylvain Defresne, Justin Novosad, Mark Cogan
Hi C++ Style Owners,

We are reaching out to request a targeted exception to the style guide's ban on std::function for a specific use case involving Swift/C++ interoperability.

We are currently investigating Swift/C++ interoperability support in Chromium that requires passing callbacks across the C++-to-Swift boundary. Swift's C++ interop layer provides native bridging support for std::function, making it the most viable path for this integration.

We are not proposing to use std::function for general callback handling or to replace Chromium's callback system.
Instead, we plan to use std::function strictly as a wrapper to transport base::RepeatingCallback and base::OnceCallback objects across the C++-to-Swift boundary. By restricting its use to a transport mechanism, we ensure that Chromium's standard callbacks still handle the underlying lifecycle and memory management.
Here is a WIP CL: https://chromium-review.googlesource.com/c/chromium/src/+/7572162

Could you let us know if this approach and exception are acceptable?

Thanks,
Asami

Avi Drissman

unread,
Feb 19, 2026, 2:34:09 PMFeb 19
to Asami Doi, c...@chromium.org, Rohit Rao, Sylvain Defresne, Justin Novosad, Mark Cogan
I would vote for this exception given the narrow scope. (I will admit to bias, being on the Mac team, so I'm hoping to hear more diverse voices as well.)

Avi

--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CALzRO2R8EjZawbwu3QopYNS7pCpuj_mPm3gSgBqT1WQ1%3DMGwXA%40mail.gmail.com.

Joe Mason

unread,
Feb 20, 2026, 4:35:21 PMFeb 20
to Avi Drissman, Asami Doi, c...@chromium.org, Rohit Rao, Sylvain Defresne, Justin Novosad, Mark Cogan
I think https://chromium.googlesource.com/chromium/src/+/main/styleguide/c++/c++-features.md#banned-features-and-third_party-code covers this use case:

Chromium code that calls functions exported from a third-party library may use banned library types that are required by the interface, as long as:

  • The disallowed type is used only at the interface, and converted to and from an equivalent allowed type as soon as practical on the Chromium side.
 

Asami Doi

unread,
Feb 23, 2026, 10:40:19 AMFeb 23
to Joe Mason, Avi Drissman, c...@chromium.org, Rohit Rao, Sylvain Defresne, Justin Novosad, Mark Cogan
Thank you for your feedback.

The guideline mentions banned features in a third-party library. In our case, this Swift/C++ interop code will reside within Chromium's own codebase (not in //third_party).
Could you confirm if this existing exception still applies to our use case?

Assuming it does, since std::function is actively flagged by Chromium's automated presubmit checks, can we bypass the presubmit entirely for those specific warnings when uploading/landing CLs? Or do you have any other guidance for landing CLs with std::function?

Thank you.

Joe Mason

unread,
Feb 23, 2026, 10:58:27 AMFeb 23
to Asami Doi, Avi Drissman, cxx, Rohit Rao, Sylvain Defresne, Justin Novosad, Mark Cogan
In my interpretation of that style guide passage, Swift's "native bridging support" is the third-party library, and the "Swift/C++ interop code... within Chromium's own codebase" would be the Chromium code. 

I'm not sure how to get an exception from the presubmit, though.

Avi Drissman

unread,
Feb 23, 2026, 11:01:03 AMFeb 23
to Asami Doi, Joe Mason, c...@chromium.org, Rohit Rao, Sylvain Defresne, Justin Novosad, Mark Cogan
I would argue that this is effectively equivalent, as being at a boundary to code we don't control, whether that is third-party code or interop code.

Avi

Asami Doi

unread,
Feb 24, 2026, 8:13:43 AMFeb 24
to Justin Novosad, Avi Drissman, Joe Mason, c...@chromium.org, Rohit Rao, Sylvain Defresne, Mark Cogan
Updating a list of exceptions in PRESUBMIT.py works well. I think this is better than bypassing the presubmit. 
https://chromium-review.googlesource.com/c/chromium/src/+/7572162

Thank you everyone for your opinions and feedback.

On Mon, Feb 23, 2026 at 8:09 PM Justin Novosad <ju...@google.com> wrote:
To codify the exception, just go to src/PRESUBMIT.py and find the "BanRule" for "std::function".  There's already a list of exceptions to that rule. You just add your file to the list.  Reference this thread in a review comment for the PRESUBMIT owner's approval.

Justin Novosad

unread,
Feb 24, 2026, 10:37:30 AMFeb 24
to Avi Drissman, Asami Doi, Joe Mason, c...@chromium.org, Rohit Rao, Sylvain Defresne, Mark Cogan
To codify the exception, just go to src/PRESUBMIT.py and find the "BanRule" for "std::function".  There's already a list of exceptions to that rule. You just add your file to the list.  Reference this thread in a review comment for the PRESUBMIT owner's approval.

On Mon, Feb 23, 2026 at 11:01 AM Avi Drissman <a...@google.com> wrote:
Reply all
Reply to author
Forward
0 new messages