From 7d80d6e5a1d64ca581ec24f589c33ddbddbb506a Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Tue, 10 Mar 2026 06:53:06 -0700 Subject: [PATCH] Use the derived class name in inherited constructors in the API snapshot (#56031) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/56031 Changelog: [Internal] Doxygen uses base class name for inherited constructors. This diff adds a guard to replace them with the derived class name in the final API snapshot. Reviewed By: cipolleschi Differential Revision: D95939080 fbshipit-source-id: 918135b8c5c603423e3a13537d9723e54ed4f035 --- scripts/cxx-api/parser/builders.py | 39 ++++++++++++++++++- .../snapshot.api | 11 ++++++ .../test.h | 24 ++++++++++++ .../snapshot.api | 6 +++ .../should_handle_conversion_operators/test.h | 19 +++++++++ 5 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 scripts/cxx-api/tests/snapshots/should_handle_constructor_inheritance/snapshot.api create mode 100644 scripts/cxx-api/tests/snapshots/should_handle_constructor_inheritance/test.h create mode 100644 scripts/cxx-api/tests/snapshots/should_handle_conversion_operators/snapshot.api create mode 100644 scripts/cxx-api/tests/snapshots/should_handle_conversion_operators/test.h diff --git a/scripts/cxx-api/parser/builders.py b/scripts/cxx-api/parser/builders.py index 545abd3502a..fb4c86f9168 100644 --- a/scripts/cxx-api/parser/builders.py +++ b/scripts/cxx-api/parser/builders.py @@ -41,6 +41,37 @@ from .utils import ( ) +###################### +# Inherited constructor fixup +###################### + + +def _fix_inherited_constructor_name( + func_member: FunctionMember, + compound_name: str, +) -> None: + """ + Fix inherited constructor names reported by Doxygen. + + When a class inherits constructors via ``using Base::Base;``, Doxygen + reports them with the base class name instead of the derived class name. + This function detects such constructors and renames them. + """ + if ( + func_member.type != "" + or func_member.name.startswith("~") + or func_member.name.startswith("operator") + ): + return + + class_unqualified_name = parse_qualified_path(compound_name)[-1] + # Strip template args for comparison + class_base_name = class_unqualified_name.split("<")[0] + + if func_member.name != class_base_name: + func_member.name = class_unqualified_name + + ###################### # Member extraction ###################### @@ -601,9 +632,13 @@ def create_class_scope( ) elif member_type == "func": for function_def in section_def.memberdef: - class_scope.add_member( - get_function_member(function_def, visibility, is_static) + func_member = get_function_member( + function_def, visibility, is_static ) + _fix_inherited_constructor_name( + func_member, compound_object.compoundname + ) + class_scope.add_member(func_member) elif member_type == "type": for member_def in section_def.memberdef: if member_def.kind == "enum": diff --git a/scripts/cxx-api/tests/snapshots/should_handle_constructor_inheritance/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_constructor_inheritance/snapshot.api new file mode 100644 index 00000000000..ae029925d82 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_handle_constructor_inheritance/snapshot.api @@ -0,0 +1,11 @@ +class test::Base { + public Base() = default; + public Base(const test::Base& other); + public Base(int test); +} + +class test::Derived : public test::Base { + public Derived() = default; + public Derived(const test::Base& other); + public Derived(int test); +} diff --git a/scripts/cxx-api/tests/snapshots/should_handle_constructor_inheritance/test.h b/scripts/cxx-api/tests/snapshots/should_handle_constructor_inheritance/test.h new file mode 100644 index 00000000000..0fe9fbb6749 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_handle_constructor_inheritance/test.h @@ -0,0 +1,24 @@ +/* + * 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 test { + +class Base { + public: + Base() = default; + Base(int test); + Base(const Base &other); +}; + +class Derived : public Base { + public: + using Base::Base; +}; + +} // namespace test diff --git a/scripts/cxx-api/tests/snapshots/should_handle_conversion_operators/snapshot.api b/scripts/cxx-api/tests/snapshots/should_handle_conversion_operators/snapshot.api new file mode 100644 index 00000000000..691784f2ab9 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_handle_conversion_operators/snapshot.api @@ -0,0 +1,6 @@ +class test::Clss { + public operator Other() const; +} + +class test::Other { +} diff --git a/scripts/cxx-api/tests/snapshots/should_handle_conversion_operators/test.h b/scripts/cxx-api/tests/snapshots/should_handle_conversion_operators/test.h new file mode 100644 index 00000000000..c6c300c0af3 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_handle_conversion_operators/test.h @@ -0,0 +1,19 @@ +/* + * 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 test { + +class Other {}; + +class Clss { + public: + operator Other() const; +}; + +} // namespace test