From 015cd13ab18f724373a0c96236e0239e1093bf2d Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Thu, 26 Mar 2026 08:40:54 -0700 Subject: [PATCH] Deduplicate base classes from Doxygen `using` declaration (#56218) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/56218 Changelog: [Internal] When a class inherits constructors via `using Base::Base;`, Doxygen incorrectly emits duplicate `basecompoundref` entries for the same base class. This caused base classes like `ConverterBase` to appear twice in the snapshot output. This diff deduplicates base classes by name in `get_base_classes()`. Reviewed By: cipolleschi Differential Revision: D98118659 fbshipit-source-id: c81f663480fda48c89e6dd625a504a78eb9d7c41 --- scripts/cxx-api/parser/builders.py | 10 +++++++ .../snapshot.api | 12 +++++++++ .../test.h | 26 +++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 scripts/cxx-api/tests/snapshots/should_deduplicate_base_classes_with_using_constructor/snapshot.api create mode 100644 scripts/cxx-api/tests/snapshots/should_deduplicate_base_classes_with_using_constructor/test.h diff --git a/scripts/cxx-api/parser/builders.py b/scripts/cxx-api/parser/builders.py index e479660ee84..3a7dc62e2ea 100644 --- a/scripts/cxx-api/parser/builders.py +++ b/scripts/cxx-api/parser/builders.py @@ -166,8 +166,14 @@ def get_base_classes( ) -> list: """ Get the base classes of a compound object. + + Deduplicates base classes by name. Doxygen can emit duplicate + ``basecompoundref`` entries when a class inherits constructors via + ``using Base::Base;`` — the using-declaration is incorrectly reported + as an additional base class reference. """ base_classes = [] + seen_names: set[str] = set() if compound_object.basecompoundref: for base in compound_object.basecompoundref: # base is a compoundRefType with: @@ -184,6 +190,10 @@ def get_base_classes( # Ignore private base classes continue + if base_name in seen_names: + continue + seen_names.add(base_name) + base_classes.append( base_class( base_name, diff --git a/scripts/cxx-api/tests/snapshots/should_deduplicate_base_classes_with_using_constructor/snapshot.api b/scripts/cxx-api/tests/snapshots/should_deduplicate_base_classes_with_using_constructor/snapshot.api new file mode 100644 index 00000000000..068fda21925 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_deduplicate_base_classes_with_using_constructor/snapshot.api @@ -0,0 +1,12 @@ +struct test::Converter : public test::ConverterBase { + public void doSomething(); +} + +template +struct test::Converter { +} + +template +struct test::ConverterBase { + public ConverterBase() = default; +} diff --git a/scripts/cxx-api/tests/snapshots/should_deduplicate_base_classes_with_using_constructor/test.h b/scripts/cxx-api/tests/snapshots/should_deduplicate_base_classes_with_using_constructor/test.h new file mode 100644 index 00000000000..c0e82719c05 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_deduplicate_base_classes_with_using_constructor/test.h @@ -0,0 +1,26 @@ +/* + * 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 { + +template +struct ConverterBase { + ConverterBase() = default; +}; + +template +struct Converter {}; + +template <> +struct Converter : public ConverterBase { + using ConverterBase::ConverterBase; + void doSomething(); +}; + +} // namespace test