Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions src/mrdocs/Metadata/Finalizers/BaseMembersFinalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2025 Alan de Freitas (alandefreitas@gmail.com)
// Copyright (c) 2026 Gennaro Prota (gennaro.prota@gmail.com)
//
// Official repository: https://github.com/cppalliance/mrdocs
//
Expand Down Expand Up @@ -67,16 +68,31 @@ inheritBaseMembers(
RecordTranche& derived,
RecordTranche const& base)
{
inheritBaseMembers(derivedId, derived.NamespaceAliases, base.NamespaceAliases);
inheritBaseMembers(derivedId, derived.Typedefs, base.Typedefs);
inheritBaseMembers(derivedId, derived.Records, base.Records);
inheritBaseMembers(derivedId, derived.Enums, base.Enums);
inheritBaseMembers(derivedId, derived.Functions, base.Functions);
inheritBaseMembers(derivedId, derived.StaticFunctions, base.StaticFunctions);
inheritBaseMembers(derivedId, derived.Variables, base.Variables);
inheritBaseMembers(derivedId, derived.StaticVariables, base.StaticVariables);
inheritBaseMembers(derivedId, derived.Concepts, base.Concepts);
inheritBaseMembers(derivedId, derived.Guides, base.Guides);
// Taken before anything is inherited, so that a member coming from a
// base is never mistaken for one the derived class declares.
std::unordered_set<std::string> const derivedNames = memberNames(derived);

describe::for_each_member<RecordTranche>([&](auto const d) {
inheritBaseMembers(
derivedId, derived.*d.pointer, base.*d.pointer, derivedNames);
});
}

std::unordered_set<std::string>
BaseMembersFinalizer::
memberNames(RecordTranche const& T) const
{
std::unordered_set<std::string> result;
describe::for_each_member<RecordTranche>([&](auto const d) {
for (SymbolID const& id: T.*d.pointer)
{
if (Symbol const* infoPtr = corpus_.find(id))
{
result.insert(infoPtr->Name);
}
}
});
return result;
}

namespace {
Expand All @@ -96,7 +112,8 @@ BaseMembersFinalizer::
inheritBaseMembers(
SymbolID const& derivedId,
std::vector<SymbolID>& derived,
std::vector<SymbolID> const& base)
std::vector<SymbolID> const& base,
std::unordered_set<std::string> const& derivedNames)
{
Symbol const* derivedInfo = nullptr;
auto const getDerivedInfo = [&]() -> Symbol const*
Expand All @@ -123,6 +140,13 @@ inheritBaseMembers(
FunctionClass::Destructor}));
}

// A using-declaration re-exports a name rather than a signature,
// so whatever the derived class declares under that name hides it,
// whichever kind of member that is. The search below cannot see
// it, since it covers the members of one kind.
MRDOCS_CHECK_OR_CONTINUE(
!otherInfo.isUsing() || !derivedNames.contains(otherInfo.Name));

// Check if derived class has a member that shadows the base member
auto shadowIt = std::ranges::find_if(
derived,
Expand Down
8 changes: 7 additions & 1 deletion src/mrdocs/Metadata/Finalizers/BaseMembersFinalizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2025 Alan de Freitas (alandefreitas@gmail.com)
// Copyright (c) 2026 Gennaro Prota (gennaro.prota@gmail.com)
//
// Official repository: https://github.com/cppalliance/mrdocs
//
Expand Down Expand Up @@ -50,7 +51,12 @@ class BaseMembersFinalizer
inheritBaseMembers(
SymbolID const& derivedId,
std::vector<SymbolID>& derived,
std::vector<SymbolID> const& base);
std::vector<SymbolID> const& base,
std::unordered_set<std::string> const& derivedNames);

// The names the members of a tranche go by.
std::unordered_set<std::string>
memberNames(RecordTranche const& T) const;

void
finalizeRecords(std::vector<SymbolID> const& ids);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// A member re-exported from a private base with a using-declaration is a
// member of the class that re-exports it, so a class deriving from that
// one inherits it like any other member.
//
// `Shadowing` declares the same name for itself, which hides the name
// the base re-exported, so only its own member is listed.

struct Base
{
int size() const;
};

struct Mid : private Base
{
using Base::size;

int count() const;
};

struct Leaf : Mid {};

struct Deeper : Leaf {};

struct Shadowing : Mid
{
void size(int);
};
Loading
Loading