diff --git a/scripts/cxx-api/parser/scope.py b/scripts/cxx-api/parser/scope.py index 64afbca2c97..b4cc776cd05 100644 --- a/scripts/cxx-api/parser/scope.py +++ b/scripts/cxx-api/parser/scope.py @@ -409,16 +409,18 @@ class Scope(Generic[ScopeKindT]): if anchor_prefix: return f"{anchor_prefix}::{suffix}" return suffix - elif any( - isinstance(m, FriendMember) and m.name == base_name - for m in current_scope._members - ): - # The name matches a friend declaration, not a real member. - # Re-qualify from the remaining segments so the type resolves - # to its actual definition rather than the friend's owning class. - remaining = "::".join(path[i:]) - return self.qualify_name(remaining) else: + # Segment not found as an inner scope or a real member of + # the current scope. When inside a struct-like scope this + # typically means Doxygen's refid-based qualification + # incorrectly placed a type under a compound that does not + # actually contain it — for example a friend declaration or + # an inherited constructor reported as a member ref. Try + # to re-qualify from the remaining unmatched segments so the + # type resolves against the broader scope hierarchy. + if isinstance(current_scope.kind, StructLikeScopeKind): + remaining = "::".join(path[i:]) + return self.qualify_name(remaining) return None # Return qualified name with preserved template arguments diff --git a/scripts/cxx-api/tests/snapshots/should_not_scope_base_class_typedef_under_derived_class/snapshot.api b/scripts/cxx-api/tests/snapshots/should_not_scope_base_class_typedef_under_derived_class/snapshot.api new file mode 100644 index 00000000000..41f269c2400 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_not_scope_base_class_typedef_under_derived_class/snapshot.api @@ -0,0 +1,9 @@ +class test::Derived : public test::Base { + public Derived(int value); + public using BaseAlias = test::Base; +} + +template +class test::Base { + public Base(int value); +} diff --git a/scripts/cxx-api/tests/snapshots/should_not_scope_base_class_typedef_under_derived_class/test.h b/scripts/cxx-api/tests/snapshots/should_not_scope_base_class_typedef_under_derived_class/test.h new file mode 100644 index 00000000000..cbfcf1c155a --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_not_scope_base_class_typedef_under_derived_class/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 { + +template +class Base { + public: + Base(int value); +}; + +class Derived : public Base { + public: + using BaseAlias = Base; + using Base::Base; +}; + +} // namespace test diff --git a/scripts/cxx-api/tests/snapshots/should_not_scope_friend_class_under_compound/snapshot.api b/scripts/cxx-api/tests/snapshots/should_not_scope_friend_class_under_compound/snapshot.api new file mode 100644 index 00000000000..dc34a4dfad7 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_not_scope_friend_class_under_compound/snapshot.api @@ -0,0 +1,7 @@ +class test::ProviderRegistry { +} + +class test::Registry { + public Registry(const test::ProviderRegistry& provider); + public bool hasItem(int handle) const; +} diff --git a/scripts/cxx-api/tests/snapshots/should_not_scope_friend_class_under_compound/test.h b/scripts/cxx-api/tests/snapshots/should_not_scope_friend_class_under_compound/test.h new file mode 100644 index 00000000000..54b18e30107 --- /dev/null +++ b/scripts/cxx-api/tests/snapshots/should_not_scope_friend_class_under_compound/test.h @@ -0,0 +1,25 @@ +/* + * 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 ProviderRegistry; + +class Registry { + public: + Registry(const ProviderRegistry &provider); + bool hasItem(int handle) const; + + private: + friend class ProviderRegistry; +}; + +class ProviderRegistry {}; + +} // namespace test