clang API Documentation
#include "clang/Sema/SemaInternal.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/CXXInheritance.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclFriend.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DependentDiagnostic.h"
#include "clang/AST/ExprCXX.h"
#include "clang/Sema/DelayedDiagnostic.h"
#include "clang/Sema/Initialization.h"
#include "clang/Sema/Lookup.h"
Go to the source code of this file.
Enumerations | |
enum | AccessResult { AR_accessible, AR_inaccessible, AR_dependent } |
A copy of Sema's enum without AR_delayed. More... | |
Functions | |
static CXXRecordDecl * | FindDeclaringClass (NamedDecl *D) |
static bool | MightInstantiateTo (const CXXRecordDecl *From, const CXXRecordDecl *To) |
Checks whether one class might instantiate to the other. | |
static AccessResult | IsDerivedFromInclusive (const CXXRecordDecl *Derived, const CXXRecordDecl *Target) |
static bool | MightInstantiateTo (Sema &S, DeclContext *Context, DeclContext *Friend) |
static bool | MightInstantiateTo (Sema &S, CanQualType Context, CanQualType Friend) |
static bool | MightInstantiateTo (Sema &S, FunctionDecl *Context, FunctionDecl *Friend) |
static bool | MightInstantiateTo (Sema &S, FunctionTemplateDecl *Context, FunctionTemplateDecl *Friend) |
static AccessResult | MatchesFriend (Sema &S, const EffectiveContext &EC, const CXXRecordDecl *Friend) |
static AccessResult | MatchesFriend (Sema &S, const EffectiveContext &EC, CanQualType Friend) |
static AccessResult | MatchesFriend (Sema &S, const EffectiveContext &EC, ClassTemplateDecl *Friend) |
static AccessResult | MatchesFriend (Sema &S, const EffectiveContext &EC, FunctionDecl *Friend) |
static AccessResult | MatchesFriend (Sema &S, const EffectiveContext &EC, FunctionTemplateDecl *Friend) |
static AccessResult | MatchesFriend (Sema &S, const EffectiveContext &EC, FriendDecl *FriendD) |
static AccessResult | GetFriendKind (Sema &S, const EffectiveContext &EC, const CXXRecordDecl *Class) |
static AccessResult | GetProtectedFriendKind (Sema &S, const EffectiveContext &EC, const CXXRecordDecl *InstanceContext, const CXXRecordDecl *NamingClass) |
static AccessResult | HasAccess (Sema &S, const EffectiveContext &EC, const CXXRecordDecl *NamingClass, AccessSpecifier Access, const AccessTarget &Target) |
static CXXBasePath * | FindBestPath (Sema &S, const EffectiveContext &EC, AccessTarget &Target, AccessSpecifier FinalAccess, CXXBasePaths &Paths) |
static bool | TryDiagnoseProtectedAccess (Sema &S, const EffectiveContext &EC, AccessTarget &Target) |
static void | diagnoseBadDirectAccess (Sema &S, const EffectiveContext &EC, AccessTarget &entity) |
static void | DiagnoseAccessPath (Sema &S, const EffectiveContext &EC, AccessTarget &entity) |
static void | DiagnoseBadAccess (Sema &S, SourceLocation Loc, const EffectiveContext &EC, AccessTarget &Entity) |
static bool | IsMicrosoftUsingDeclarationAccessBug (Sema &S, SourceLocation AccessLoc, AccessTarget &Entity) |
static AccessResult | IsAccessible (Sema &S, const EffectiveContext &EC, AccessTarget &Entity) |
static void | DelayDependentAccess (Sema &S, const EffectiveContext &EC, SourceLocation Loc, const AccessTarget &Entity) |
static AccessResult | CheckEffectiveAccess (Sema &S, const EffectiveContext &EC, SourceLocation Loc, AccessTarget &Entity) |
Checks access to an entity from the given effective context. | |
static Sema::AccessResult | CheckAccess (Sema &S, SourceLocation Loc, AccessTarget &Entity) |
enum AccessResult |
A copy of Sema's enum without AR_delayed.
Definition at line 30 of file SemaAccess.cpp.
static Sema::AccessResult CheckAccess | ( | Sema & | S, |
SourceLocation | Loc, | ||
AccessTarget & | Entity | ||
) | [static] |
Definition at line 1437 of file SemaAccess.cpp.
References clang::Sema::DelayedDiagnostics::add(), AR_accessible, clang::Sema::AR_accessible, clang::Sema::AR_delayed, AR_dependent, AR_inaccessible, clang::AS_public, CheckEffectiveAccess(), clang::Sema::CurContext, clang::Sema::DelayedDiagnostics, clang::sema::DelayedDiagnostic::makeAccess(), and clang::Sema::DelayedDiagnostics::shouldDelayDiagnostics().
Referenced by clang::Sema::CheckAddressOfMemberAccess(), clang::Sema::CheckAllocationAccess(), clang::Sema::CheckBaseClassAccess(), clang::Sema::CheckConstructorAccess(), clang::Sema::CheckDestructorAccess(), clang::Sema::CheckLookupAccess(), clang::Sema::CheckMemberAccess(), clang::Sema::CheckMemberOperatorAccess(), clang::Sema::CheckUnresolvedLookupAccess(), clang::Sema::CheckUnresolvedMemberAccess(), clang::Sema::HandleDependentAccessCheck(), and clang::Sema::isSpecialMemberAccessibleForDeletion().
static AccessResult CheckEffectiveAccess | ( | Sema & | S, |
const EffectiveContext & | EC, | ||
SourceLocation | Loc, | ||
AccessTarget & | Entity | ||
) | [static] |
Checks access to an entity from the given effective context.
Definition at line 1410 of file SemaAccess.cpp.
References AR_accessible, AR_dependent, AR_inaccessible, clang::AS_public, DelayDependentAccess(), DiagnoseBadAccess(), clang::Sema::getLangOpts(), IsAccessible(), and IsMicrosoftUsingDeclarationAccessBug().
Referenced by CheckAccess(), clang::Sema::CheckBaseClassAccess(), clang::Sema::CheckFriendAccess(), and clang::Sema::HandleDelayedAccessCheck().
static void DelayDependentAccess | ( | Sema & | S, |
const EffectiveContext & | EC, | ||
SourceLocation | Loc, | ||
const AccessTarget & | Entity | ||
) | [static] |
Definition at line 1392 of file SemaAccess.cpp.
References clang::DependentDiagnostic::Access, clang::Sema::Context, and clang::DependentDiagnostic::Create().
Referenced by CheckEffectiveAccess().
static void DiagnoseAccessPath | ( | Sema & | S, |
const EffectiveContext & | EC, | ||
AccessTarget & | entity | ||
) | [static] |
Diagnose the path which caused the given declaration or base class to become inaccessible.
Definition at line 1150 of file SemaAccess.cpp.
References clang::CXXBasePath::Access, AR_accessible, AR_dependent, AR_inaccessible, clang::AS_none, clang::AS_private, clang::AS_protected, clang::AS_public, clang::Sema::Diag(), diagnoseBadDirectAccess(), FindBestPath(), clang::Decl::getAccess(), clang::CXXBaseSpecifier::getAccessSpecifier(), clang::CXXBaseSpecifier::getAccessSpecifierAsWritten(), clang::SourceRange::getBegin(), clang::CXXRecordDecl::getCanonicalDecl(), clang::CXXBaseSpecifier::getSourceRange(), and HasAccess().
Referenced by DiagnoseBadAccess().
static void DiagnoseBadAccess | ( | Sema & | S, |
SourceLocation | Loc, | ||
const EffectiveContext & | EC, | ||
AccessTarget & | Entity | ||
) | [static] |
Definition at line 1259 of file SemaAccess.cpp.
References clang::AS_protected, clang::Sema::Context, clang::Sema::Diag(), DiagnoseAccessPath(), clang::NamedDecl::getDeclName(), and clang::ASTContext::getTypeDeclType().
Referenced by CheckEffectiveAccess().
static void diagnoseBadDirectAccess | ( | Sema & | S, |
const EffectiveContext & | EC, | ||
AccessTarget & | entity | ||
) | [static] |
We are unable to access a given declaration due to its direct access control; diagnose that.
Definition at line 1093 of file SemaAccess.cpp.
References clang::AS_protected, clang::DeclContext::decls(), clang::Sema::Diag(), FindDeclaringClass(), clang::DeclContext::getParent(), clang::Decl::getPreviousDecl(), and TryDiagnoseProtectedAccess().
Referenced by DiagnoseAccessPath().
static CXXBasePath* FindBestPath | ( | Sema & | S, |
const EffectiveContext & | EC, | ||
AccessTarget & | Target, | ||
AccessSpecifier | FinalAccess, | ||
CXXBasePaths & | Paths | ||
) | [static] |
Finds the best path from the naming class to the declaring class, taking friend declarations into account.
C++0x [class.access.base]p5: A member m is accessible at the point R when named in class N if [M1] m as a member of N is public, or [M2] m as a member of N is private, and R occurs in a member or friend of class N, or [M3] m as a member of N is protected, and R occurs in a member or friend of class N, or in a member or friend of a class P derived from N, where m as a member of P is public, private, or protected, or [M4] there exists a base class B of N that is accessible at R, and m is accessible at R when named in class B.
C++0x [class.access.base]p4: A base class B of N is accessible at R, if [B1] an invented public member of B would be a public member of N, or [B2] R occurs in a member or friend of class N, and an invented public member of B would be a private or protected member of N, or [B3] R occurs in a member or friend of a class P derived from N, and an invented public member of B would be a private or protected member of P, or [B4] there exists a class S such that B is a base class of S accessible at R and S is a base class of N accessible at R.
Along a single inheritance path we can restate both of these iteratively:
First, we note that M1-4 are equivalent to B1-4 if the member is treated as a notional base of its declaring class with inheritance access equivalent to the member's access. Therefore we need only ask whether a class B is accessible from a class N in context R.
Let B_1 .. B_n be the inheritance path in question (i.e. where B_1 = N, B_n = B, and for all i, B_{i+1} is a direct base class of B_i). For i in 1..n, we will calculate ACAB(i), the access to the closest accessible base in the path: Access(a, b) = (* access on the base specifier from a to b *) Merge(a, forbidden) = forbidden Merge(a, private) = forbidden Merge(a, b) = min(a,b) Accessible(c, forbidden) = false Accessible(c, private) = (R is c) || IsFriend(c, R) Accessible(c, protected) = (R derived from c) || IsFriend(c, R) Accessible(c, public) = true ACAB(n) = public ACAB(i) = let AccessToBase = Merge(Access(B_i, B_{i+1}), ACAB(i+1)) in if Accessible(B_i, AccessToBase) then public else AccessToBase
B is an accessible base of N at R iff ACAB(1) = public.
FinalAccess | the access of the "final step", or AS_public if there is no final step. |
Definition at line 926 of file SemaAccess.cpp.
References clang::CXXBasePath::Access, AR_accessible, AR_dependent, AR_inaccessible, clang::AS_none, clang::AS_private, clang::AS_public, clang::CXXBasePaths::begin(), clang::CXXBasePaths::end(), clang::CXXRecordDecl::getCanonicalDecl(), HasAccess(), and clang::CXXRecordDecl::isDerivedFrom().
Referenced by DiagnoseAccessPath(), and IsAccessible().
static CXXRecordDecl* FindDeclaringClass | ( | NamedDecl * | D | ) | [static] |
Definition at line 65 of file SemaAccess.cpp.
References clang::Decl::getDeclContext(), and clang::RecordDecl::isAnonymousStructOrUnion().
Referenced by diagnoseBadDirectAccess().
static AccessResult GetFriendKind | ( | Sema & | S, |
const EffectiveContext & | EC, | ||
const CXXRecordDecl * | Class | ||
) | [static] |
Definition at line 569 of file SemaAccess.cpp.
References AR_accessible, AR_dependent, AR_inaccessible, clang::CXXRecordDecl::friends(), and MatchesFriend().
Referenced by GetProtectedFriendKind(), and HasAccess().
static AccessResult GetProtectedFriendKind | ( | Sema & | S, |
const EffectiveContext & | EC, | ||
const CXXRecordDecl * | InstanceContext, | ||
const CXXRecordDecl * | NamingClass | ||
) | [static] |
Search for a class P that EC is a friend of, under the constraint InstanceContext <= P if InstanceContext exists, or else NamingClass <= P and with the additional restriction that a protected member of NamingClass would have some natural access in P, which implicitly imposes the constraint that P <= NamingClass.
This isn't quite the condition laid out in the standard. Instead of saying that a notional protected member of NamingClass would have to have some natural access in P, it says the actual target has to have some natural access in P, which opens up the possibility that the target (which is not necessarily a member of NamingClass) might be more accessible along some path not passing through it. That's really a bad idea, though, because it introduces two problems:
Definition at line 710 of file SemaAccess.cpp.
References AR_accessible, AR_dependent, AR_inaccessible, clang::CXXRecordDecl::getCanonicalDecl(), and GetFriendKind().
Referenced by HasAccess().
static AccessResult HasAccess | ( | Sema & | S, |
const EffectiveContext & | EC, | ||
const CXXRecordDecl * | NamingClass, | ||
AccessSpecifier | Access, | ||
const AccessTarget & | Target | ||
) | [static] |
Definition at line 728 of file SemaAccess.cpp.
References AR_accessible, AR_dependent, AR_inaccessible, clang::AS_private, clang::AS_protected, clang::AS_public, clang::CXXRecordDecl::getCanonicalDecl(), GetFriendKind(), clang::Sema::getLangOpts(), GetProtectedFriendKind(), IsDerivedFromInclusive(), and MightInstantiateTo().
Referenced by DiagnoseAccessPath(), FindBestPath(), and IsAccessible().
static AccessResult IsAccessible | ( | Sema & | S, |
const EffectiveContext & | EC, | ||
AccessTarget & | Entity | ||
) | [static] |
Determines whether the accessed entity is accessible. Public members have been weeded out by this point.
Definition at line 1314 of file SemaAccess.cpp.
References clang::CXXBasePath::Access, AR_accessible, AR_dependent, AR_inaccessible, clang::AS_none, clang::AS_public, FindBestPath(), clang::Decl::getAccess(), and HasAccess().
Referenced by CheckEffectiveAccess(), and clang::Sema::IsSimplyAccessible().
static AccessResult IsDerivedFromInclusive | ( | const CXXRecordDecl * | Derived, |
const CXXRecordDecl * | Target | ||
) | [static] |
Checks whether one class is derived from another, inclusively. Properly indicates when it couldn't be determined due to dependence.
This should probably be donated to AST or at least Sema.
Definition at line 274 of file SemaAccess.cpp.
References AR_accessible, AR_dependent, AR_inaccessible, clang::CXXRecordDecl::bases(), clang::Type::getAs(), clang::CXXRecordDecl::getCanonicalDecl(), clang::CXXRecordDecl::hasDefinition(), clang::DeclContext::isDependentContext(), clang::Type::isDependentType(), and MightInstantiateTo().
Referenced by HasAccess(), and TryDiagnoseProtectedAccess().
static bool IsMicrosoftUsingDeclarationAccessBug | ( | Sema & | S, |
SourceLocation | AccessLoc, | ||
AccessTarget & | Entity | ||
) | [static] |
MSVC has a bug where if during an using declaration name lookup, the declaration found is unaccessible (private) and that declaration was bring into scope via another using declaration whose target declaration is accessible (public) then no error is generated. Example: class A { public: int f(); }; class B : public A { private: using A::f; }; class C : public B { private: using B::f; };
Here, B::f is private so this should fail in Standard C++, but because B::f refers to A::f which is public MSVC accepts it.
Definition at line 1294 of file SemaAccess.cpp.
References clang::AS_private, clang::AS_protected, clang::AS_public, clang::Sema::Diag(), clang::Decl::getAccess(), and clang::NamedDecl::getQualifiedNameAsString().
Referenced by CheckEffectiveAccess().
static AccessResult MatchesFriend | ( | Sema & | S, |
const EffectiveContext & | EC, | ||
const CXXRecordDecl * | Friend | ||
) | [static] |
Definition at line 401 of file SemaAccess.cpp.
References AR_accessible, AR_dependent, AR_inaccessible, clang::Sema::Context, clang::ASTContext::getCanonicalType(), clang::ASTContext::getTypeDeclType(), and MightInstantiateTo().
Referenced by GetFriendKind(), and MatchesFriend().
static AccessResult MatchesFriend | ( | Sema & | S, |
const EffectiveContext & | EC, | ||
CanQualType | Friend | ||
) | [static] |
Definition at line 423 of file SemaAccess.cpp.
References AR_dependent, AR_inaccessible, clang::CanQual< T >::getAs(), and MatchesFriend().
static AccessResult MatchesFriend | ( | Sema & | S, |
const EffectiveContext & | EC, | ||
ClassTemplateDecl * | Friend | ||
) | [static] |
Determines whether the given friend class template matches anything in the effective context.
Definition at line 438 of file SemaAccess.cpp.
References AR_accessible, AR_dependent, AR_inaccessible, clang::ClassTemplateDecl::getCanonicalDecl(), clang::Decl::getDeclContext(), clang::NamedDecl::getDeclName(), clang::CXXRecordDecl::getDescribedClassTemplate(), MightInstantiateTo(), and Record.
static AccessResult MatchesFriend | ( | Sema & | S, |
const EffectiveContext & | EC, | ||
FunctionDecl * | Friend | ||
) | [static] |
Determines whether the given friend function matches anything in the effective context.
Definition at line 491 of file SemaAccess.cpp.
References AR_accessible, AR_dependent, AR_inaccessible, and MightInstantiateTo().
static AccessResult MatchesFriend | ( | Sema & | S, |
const EffectiveContext & | EC, | ||
FunctionTemplateDecl * | Friend | ||
) | [static] |
Determines whether the given friend function template matches anything in the effective context.
Definition at line 510 of file SemaAccess.cpp.
References AR_accessible, AR_dependent, AR_inaccessible, clang::FunctionTemplateDecl::getCanonicalDecl(), and MightInstantiateTo().
static AccessResult MatchesFriend | ( | Sema & | S, |
const EffectiveContext & | EC, | ||
FriendDecl * | FriendD | ||
) | [static] |
Determines whether the given friend declaration matches anything in the effective context.
Definition at line 540 of file SemaAccess.cpp.
References AR_accessible, clang::Decl::getCanonicalDecl(), clang::FriendDecl::getFriendDecl(), clang::FriendDecl::getFriendType(), clang::Decl::isInvalidDecl(), clang::FriendDecl::isUnsupportedFriend(), and MatchesFriend().
static bool MightInstantiateTo | ( | const CXXRecordDecl * | From, |
const CXXRecordDecl * | To | ||
) | [static] |
Checks whether one class might instantiate to the other.
Definition at line 254 of file SemaAccess.cpp.
References clang::Decl::getDeclContext(), clang::NamedDecl::getDeclName(), clang::DeclContext::getPrimaryContext(), and clang::DeclContext::isFileContext().
Referenced by HasAccess(), IsDerivedFromInclusive(), MatchesFriend(), and MightInstantiateTo().
static bool MightInstantiateTo | ( | Sema & | S, |
DeclContext * | Context, | ||
DeclContext * | Friend | ||
) | [static] |
Definition at line 324 of file SemaAccess.cpp.
References clang::DeclContext::isDependentContext(), and clang::DeclContext::isFileContext().
static bool MightInstantiateTo | ( | Sema & | S, |
CanQualType | Context, | ||
CanQualType | Friend | ||
) | [static] |
Definition at line 344 of file SemaAccess.cpp.
static bool MightInstantiateTo | ( | Sema & | S, |
FunctionDecl * | Context, | ||
FunctionDecl * | Friend | ||
) | [static] |
Definition at line 355 of file SemaAccess.cpp.
References clang::Sema::Context, clang::ASTContext::getCanonicalType(), clang::Decl::getDeclContext(), clang::NamedDecl::getDeclName(), clang::CanQual< T >::getQualifiers(), clang::ValueDecl::getType(), and MightInstantiateTo().
static bool MightInstantiateTo | ( | Sema & | S, |
FunctionTemplateDecl * | Context, | ||
FunctionTemplateDecl * | Friend | ||
) | [static] |
Definition at line 393 of file SemaAccess.cpp.
References clang::FunctionTemplateDecl::getTemplatedDecl(), and MightInstantiateTo().
static bool TryDiagnoseProtectedAccess | ( | Sema & | S, |
const EffectiveContext & | EC, | ||
AccessTarget & | Target | ||
) | [static] |
Given that an entity has protected natural access, check whether access might be denied because of the protected member access restriction.
Definition at line 1018 of file SemaAccess.cpp.
References AR_accessible, AR_dependent, AR_inaccessible, clang::Sema::Context, clang::Sema::Diag(), clang::Decl::getAsFunction(), clang::Decl::getLocation(), clang::ASTContext::getTypeDeclType(), and IsDerivedFromInclusive().
Referenced by diagnoseBadDirectAccess().