-
Notifications
You must be signed in to change notification settings - Fork 60
Fix: Resolve inherited members through implicit UsingShadowDecls #1038
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8a0a6b6
c51f1c9
3f3854e
69db999
5589a8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1193,6 +1193,39 @@ | |||||
| return (clang::NamedDecl*)-1; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| static clang::UsingShadowDecl *CreateInheritedUsingShadow( | ||||||
| clang::CXXRecordDecl *Record, clang::NamedDecl *Target) { | ||||||
| if (!Record || !Target) | ||||||
| return nullptr; | ||||||
|
|
||||||
| if (auto *Shadow = llvm::dyn_cast<clang::UsingShadowDecl>(Target)) | ||||||
| Target = Shadow->getTargetDecl(); | ||||||
|
|
||||||
| if (!Target) | ||||||
| return nullptr; | ||||||
|
|
||||||
| if (Target->getDeclContext() == Record) | ||||||
| return llvm::dyn_cast<clang::UsingShadowDecl>(Target); | ||||||
|
|
||||||
| clang::ASTContext &C = Record->getASTContext(); | ||||||
| clang::DeclarationNameInfo NameInfo(Target->getDeclName(), | ||||||
| clang::SourceLocation()); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: use nullptr [modernize-use-nullptr]
Suggested change
|
||||||
| auto *Using = clang::UsingDecl::Create(C, Record, clang::SourceLocation(), | ||||||
| clang::NestedNameSpecifierLoc(), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: use nullptr [modernize-use-nullptr]
Suggested change
|
||||||
| NameInfo, false); | ||||||
| Using->setImplicit(true); | ||||||
|
|
||||||
| auto *Shadow = clang::UsingShadowDecl::Create( | ||||||
| C, Record, clang::SourceLocation(), Target->getDeclName(), Using, | ||||||
| Target); | ||||||
|
|
||||||
| Using->addShadowDecl(Shadow); | ||||||
| Record->addDecl(Shadow); | ||||||
|
|
||||||
| return Shadow; | ||||||
| } | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: no header providing "CppInternal::utils::Lookup::Named" is directly included [misc-include-cleaner] lib/CppInterOp/CppInterOp.cpp:10: - #include "Unwrap.h"
+ #include "CppInterOpInterpreter.h"
+ #include "Unwrap.h" |
||||||
|
|
||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast] hin);
^
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr] hin);
^ |
||||||
| // Cheap probe: does any namespace from `DC` up to TU carry at least | ||||||
| // one using-directive? Gates the synthetic-DRef-chain build below so | ||||||
| // the common case (no using-directives anywhere on the path) doesn't | ||||||
|
|
@@ -1228,7 +1261,43 @@ | |||||
| // null, so TU-level using-directives are already handled there. | ||||||
| auto* ND = CppInternal::utils::Lookup::Named(&getSema(), name, Within); | ||||||
| if (ND && ND != (clang::NamedDecl*)-1) | ||||||
| return INTEROP_RETURN(ND->getCanonicalDecl()); | ||||||
| return INTEROP_RETURN(ND); | ||||||
|
|
||||||
| // Qualified lookup can miss inherited members in class scope. Try the | ||||||
| // record's own lookup, which includes direct members, and then fall back | ||||||
| // to unqualified lookup inside the record to honor base-class member | ||||||
| // visibility semantics. | ||||||
| if (Within) { | ||||||
| if (auto* RD = llvm::dyn_cast<clang::CXXRecordDecl>(Within)) { | ||||||
| clang::DeclarationName DName = &getSema().Context.Idents.get(name); | ||||||
| auto Decls = RD->lookup(DName); | ||||||
| clang::NamedDecl* FoundND = nullptr; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast] hin);
^
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr] hin);
^ |
||||||
| for (auto* D : Decls) { | ||||||
| if (auto* Named = llvm::dyn_cast<clang::NamedDecl>(D)) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast] hin);
^
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr] hin);
^ |
||||||
| if (!FoundND) | ||||||
| FoundND = Named; | ||||||
| else | ||||||
| return INTEROP_RETURN(nullptr); | ||||||
| } | ||||||
| } | ||||||
| if (FoundND) | ||||||
| return INTEROP_RETURN((FoundND)); | ||||||
|
|
||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use const_cast to remove const qualifier [cppcoreguidelines-pro-type-const-cast] DRef.
^ |
||||||
| // Qualified lookup may still miss inherited class members in some | ||||||
| // record contexts. Use unqualified lookup from a synthesized point | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use const_cast to remove const qualifier [cppcoreguidelines-pro-type-const-cast] DRef.
^ |
||||||
| // inside the class to traverse base classes and find the member. | ||||||
| auto* ND2 = LookupUnqualified(getSema(), DName, Within); | ||||||
| if (ND2 == reinterpret_cast<clang::NamedDecl*>(-1)) | ||||||
| return INTEROP_RETURN(nullptr); | ||||||
| if (ND2) { | ||||||
| if (auto* Shadow = CreateInheritedUsingShadow(RD, ND2)) | ||||||
| return INTEROP_RETURN(Shadow); | ||||||
| return INTEROP_RETURN(ND2); | ||||||
| } | ||||||
| if (ND2 == (clang::NamedDecl*)-1) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast] }
^
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr] }
^ |
||||||
| return INTEROP_RETURN(nullptr); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Slow path: only when qualified lookup missed AND `Within` is a | ||||||
| // namespace whose enclosing chain carries at least one using-directive | ||||||
|
|
@@ -1240,7 +1309,7 @@ | |||||
| clang::DeclarationName DName = &getSema().Context.Idents.get(name); | ||||||
| ND = LookupUnqualified(getSema(), DName, Within); | ||||||
| if (ND && ND != (clang::NamedDecl*)-1) | ||||||
| return INTEROP_RETURN(ND->getCanonicalDecl()); | ||||||
| return INTEROP_RETURN(ND); | ||||||
|
|
||||||
| return INTEROP_RETURN(nullptr); | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: 'CreateInheritedUsingShadow' is a static definition in anonymous namespace; static is redundant here [readability-static-definition-in-anonymous-namespace]