From d0ec2956f8f43c416e02298fdcc3896569f10595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ma=C5=82ecki?= Date: Wed, 18 Mar 2026 09:29:02 -0700 Subject: [PATCH] Fix handling of member function pointers in the API snapshot (#56069) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/56069 Changelog: [Internal] Fixes handling of member function pointers in the C++ Api snapshot. Reviewed By: cipolleschi Differential Revision: D96279461 fbshipit-source-id: 42e7b004878eedfbbb8504345165bb1d60acde78 --- scripts/cxx-api/parser/builders.py | 15 +++++++++++++ .../snapshot.api | 6 ++++++ .../test.h | 21 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 scripts/cxx-api/tests/snapshots/should_handle_pointer_to_member_function_param/snapshot.api create mode 100644 scripts/cxx-api/tests/snapshots/should_handle_pointer_to_member_function_param/test.h diff --git a/scripts/cxx-api/parser/builders.py b/scripts/cxx-api/parser/builders.py index 1122433b9c1..f72c62f45e2 100644 --- a/scripts/cxx-api/parser/builders.py +++ b/scripts/cxx-api/parser/builders.py @@ -317,6 +317,21 @@ def get_doxygen_params( else: param_type += param_array + # Handle pointer-to-member-function types where the name must be + # embedded inside the declarator group. Doxygen gives: + # type = "void(ns::*)() const", name = "asFoo" + # We need to produce: + # "void(ns::*asFoo)() const" + if param_name: + m = re.search(r"\([^)]*::\*\)", param_type) + if m: + # Insert name before the closing ')' of the ptr-to-member group + insert_pos = m.end() - 1 + param_type = ( + param_type[:insert_pos] + param_name + param_type[insert_pos:] + ) + param_name = None + qualifiers, core_type = extract_qualifiers(param_type) arguments.append((qualifiers, core_type, param_name, param_default)) diff --git a/scripts/cxx-api/tests/snapshots/should_handle_pointer_to_member_function_param/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_pointer_to_member_function_param/snapshot.api new file mode 100644 index 00000000000..3df3cf570ce --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_handle_pointer_to_member_function_param/snapshot.api @@ -0,0 +1,6 @@ +struct folly::dynamic { +} + + +template +R test::jsArg(const folly::dynamic& arg, R(folly::dynamic::*asFoo)() const, const T &... desc); diff --git a/scripts/cxx-api/tests/snapshots/should_handle_pointer_to_member_function_param/test.h b/scripts/cxx-api/tests/snapshots/should_handle_pointer_to_member_function_param/test.h new file mode 100644 index 00000000000..8aaea82b5a1 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_handle_pointer_to_member_function_param/test.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +namespace folly { + +struct dynamic {}; + +} // namespace folly + +namespace test { + +template +R jsArg(const folly::dynamic &arg, R (folly::dynamic::*asFoo)() const, const T &...desc); + +} // namespace test