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