diff options
author | Matheus Izvekov <mizvekov@gmail.com> | 2025-03-21 13:20:52 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-21 13:20:52 -0300 |
commit | 14f7bd63b95d0f61a6f47119ac66398ca230559a (patch) | |
tree | 0ce077dc0293fd9ccb3987b9bb108344a90b9094 /clang/lib/Sema/SemaAccess.cpp | |
parent | 4dd7feab2bc81273f72c494f17ae0dc9661fdcf8 (diff) | |
download | llvm-14f7bd63b95d0f61a6f47119ac66398ca230559a.zip llvm-14f7bd63b95d0f61a6f47119ac66398ca230559a.tar.gz llvm-14f7bd63b95d0f61a6f47119ac66398ca230559a.tar.bz2 |
Reland: [clang] preserve class type sugar when taking pointer to member (#132401)
Original PR: #130537
Originally reverted due to revert of dependent commit. Relanding with no
changes.
This changes the MemberPointerType representation to use a
NestedNameSpecifier instead of a Type to represent the base class.
Since the qualifiers are always parsed as nested names, there was an
impedance mismatch when converting these back and forth into types, and
this led to issues in preserving sugar.
The nested names are indeed a better match for these, as the differences
which a QualType can represent cannot be expressed syntatically, and
they represent the use case more exactly, being either dependent or
referring to a CXXRecord, unqualified.
This patch also makes the MemberPointerType able to represent sugar for
a {up/downcast}cast conversion of the base class, although for now the
underlying type is canonical, as preserving the sugar up to that point
requires further work.
As usual, includes a few drive-by fixes in order to make use of the
improvements.
Diffstat (limited to 'clang/lib/Sema/SemaAccess.cpp')
-rw-r--r-- | clang/lib/Sema/SemaAccess.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp index 4ba46a9..b77cbdb 100644 --- a/clang/lib/Sema/SemaAccess.cpp +++ b/clang/lib/Sema/SemaAccess.cpp @@ -1873,21 +1873,20 @@ Sema::AccessResult Sema::CheckAddressOfMemberAccess(Expr *OvlExpr, return CheckAccess(*this, Ovl->getNameLoc(), Entity); } -Sema::AccessResult Sema::CheckBaseClassAccess(SourceLocation AccessLoc, - QualType Base, QualType Derived, - const CXXBasePath &Path, - unsigned DiagID, bool ForceCheck, - bool ForceUnprivileged) { +Sema::AccessResult Sema::CheckBaseClassAccess( + SourceLocation AccessLoc, CXXRecordDecl *Base, CXXRecordDecl *Derived, + const CXXBasePath &Path, unsigned DiagID, + llvm::function_ref<void(PartialDiagnostic &)> SetupPDiag, bool ForceCheck, + bool ForceUnprivileged) { if (!ForceCheck && !getLangOpts().AccessControl) return AR_accessible; if (Path.Access == AS_public) return AR_accessible; - AccessTarget Entity(Context, AccessTarget::Base, Base->getAsCXXRecordDecl(), - Derived->getAsCXXRecordDecl(), Path.Access); + AccessTarget Entity(Context, AccessTarget::Base, Base, Derived, Path.Access); if (DiagID) - Entity.setDiag(DiagID) << Derived << Base; + SetupPDiag(Entity.setDiag(DiagID)); if (ForceUnprivileged) { switch ( @@ -1904,6 +1903,17 @@ Sema::AccessResult Sema::CheckBaseClassAccess(SourceLocation AccessLoc, return CheckAccess(*this, AccessLoc, Entity); } +Sema::AccessResult Sema::CheckBaseClassAccess(SourceLocation AccessLoc, + QualType Base, QualType Derived, + const CXXBasePath &Path, + unsigned DiagID, bool ForceCheck, + bool ForceUnprivileged) { + return CheckBaseClassAccess( + AccessLoc, Base->getAsCXXRecordDecl(), Derived->getAsCXXRecordDecl(), + Path, DiagID, [&](PartialDiagnostic &PD) { PD << Derived << Base; }, + ForceCheck, ForceUnprivileged); +} + void Sema::CheckLookupAccess(const LookupResult &R) { assert(getLangOpts().AccessControl && "performing access check without access control"); |