Preserve using-declaration access for inherited methods#995
Open
guitargeek wants to merge 1 commit into
Open
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #995 +/- ##
==========================================
+ Coverage 82.78% 82.83% +0.05%
==========================================
Files 15 15
Lines 5048 5069 +21
==========================================
+ Hits 4179 4199 +20
- Misses 869 870 +1
🚀 New features to boost your workflow:
|
When `GetClassDecls<CXXMethodDecl>` walked a class's decls and hit a
`UsingShadowDecl` whose target is a method, it pushed the *target*
`CXXMethodDecl` from the base class. The target's `getAccess()` returns
the access in the base (e.g. `protected`); the elevated access carried
by the using-declaration (`public` in the introducing class) was
silently lost. Consumers like CPyCppyy filter on `IsPublicMethod`, so a
republished overload such as
class Base { protected: void foo(int, int); };
class Derived: public Base {
public:
using Base::foo;
void foo(int);
};
would never reach the Python proxy - calling `derived.foo(1, 2)` from
cppyy raised `TypeError: takes at most 1 arguments (2 given)`
(cppyy issue compiler-research/cppyy#220).
Push the `UsingShadowDecl` itself (for the non-constructor case;
constructor-using-shadows still go through `findInheritingConstructor`)
and teach `CheckMethodAccess` to consult `USD->getAccess()`. A small
`UnwrapUsingShadowToFunction` helper unwraps the shadow at the entry
of every API that downcasts a `TCppFunction_t` to `FunctionDecl`
(return type, arg counts/types/names/defaults, signature,
IsConst/Static/Virtual/Constructor/Destructor/Templated/Explicit,
function address, operator arity).
`MakeFunctionCallable` keeps the unwrapped target as the wrapped
function but threads a `relaxAccessControl` flag into `make_wrapper`
when the caller passed a using-shadow: the generated wrapper still
references the target by its original qualified name (e.g.
`((Base*)obj)->Base::foo(...)`), so access control has to be relaxed
during wrapper compilation for it to compile. The runtime call is
well-defined because the using-declaration made the member reachable
through the derived class.
Adds a `FunctionReflection_GetClassMethods_UsingShadowAccess`
regression test covering both the public-promoted case from the issue
and a protected-using control case (which must stay hidden).
Fixes: compiler-research/cppyy#220
vgvassilev
reviewed
May 12, 2026
| if (auto* USD = llvm::dyn_cast_or_null<UsingShadowDecl>(D)) { | ||
| if (llvm::isa_and_nonnull<CXXMethodDecl>(USD->getTargetDecl())) | ||
| return USD->getAccess() == AS; | ||
| } |
Contributor
There was a problem hiding this comment.
Why not using UnwrapUsingShadowToFunction?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
GetClassDecls<CXXMethodDecl>walked a class's decls and hit aUsingShadowDeclwhose target is a method, it pushed the targetCXXMethodDeclfrom the base class. The target'sgetAccess()returns the access in the base (e.g.protected); the elevated access carried by the using-declaration (publicin the introducing class) was silently lost. Consumers like CPyCppyy filter onIsPublicMethod, so a republished overload such aswould never reach the Python proxy - calling
derived.foo(1, 2)from cppyy raisedTypeError: takes at most 1 arguments (2 given)(cppyy issue compiler-research/cppyy#220).Push the
UsingShadowDeclitself (for the non-constructor case; constructor-using-shadows still go throughfindInheritingConstructor) and teachCheckMethodAccessto consultUSD->getAccess(). A smallUnwrapUsingShadowToFunctionhelper unwraps the shadow at the entry of every API that downcasts aTCppFunction_ttoFunctionDecl(return type, arg counts/types/names/defaults, signature, IsConst/Static/Virtual/Constructor/Destructor/Templated/Explicit, function address, operator arity).MakeFunctionCallablekeeps the unwrapped target as the wrapped function but threads arelaxAccessControlflag intomake_wrapperwhen the caller passed a using-shadow: the generated wrapper still references the target by its original qualified name (e.g.((Base*)obj)->Base::foo(...)), so access control has to be relaxed during wrapper compilation for it to compile. The runtime call is well-defined because the using-declaration made the member reachable through the derived class.Adds a
FunctionReflection_GetClassMethods_UsingShadowAccessregression test covering both the public-promoted case from the issue and a protected-using control case (which must stay hidden).Fixes: compiler-research/cppyy#220