aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2010-04-21 18:47:17 +0000
committerAnders Carlsson <andersca@mac.com>2010-04-21 18:47:17 +0000
commit9a68a67c6ae4982001815cc04f69b8781058263a (patch)
tree1e7092526e04aaf5918bdf15e633110c25fa39d0 /lib/Sema
parentc2a9b7973922cab0c0c56d46829d232ce3f4aacf (diff)
Pass the InitializedEntity to Sema::CheckConstructorAccess and use it to report different diagnostics depending on which entity is being initialized.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102010 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r--lib/Sema/Sema.h1
-rw-r--r--lib/Sema/SemaAccess.cpp21
-rw-r--r--lib/Sema/SemaInit.cpp6
3 files changed, 20 insertions, 8 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 636bb6a3d3..1506d8c2dc 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -2644,6 +2644,7 @@ public:
DeclAccessPair FoundDecl);
AccessResult CheckConstructorAccess(SourceLocation Loc,
CXXConstructorDecl *D,
+ const InitializedEntity &Entity,
AccessSpecifier Access);
AccessResult CheckDestructorAccess(SourceLocation Loc,
CXXDestructorDecl *Dtor,
diff --git a/lib/Sema/SemaAccess.cpp b/lib/Sema/SemaAccess.cpp
index 352477b859..1658b699c6 100644
--- a/lib/Sema/SemaAccess.cpp
+++ b/lib/Sema/SemaAccess.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "Sema.h"
+#include "SemaInit.h"
#include "Lookup.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/CXXInheritance.h"
@@ -1127,18 +1128,28 @@ Sema::AccessResult Sema::CheckDestructorAccess(SourceLocation Loc,
/// Checks access to a constructor.
Sema::AccessResult Sema::CheckConstructorAccess(SourceLocation UseLoc,
CXXConstructorDecl *Constructor,
+ const InitializedEntity &Entity,
AccessSpecifier Access) {
if (!getLangOptions().AccessControl ||
Access == AS_public)
return AR_accessible;
CXXRecordDecl *NamingClass = Constructor->getParent();
- AccessTarget Entity(Context, AccessTarget::Member, NamingClass,
- DeclAccessPair::make(Constructor, Access),
- QualType());
- Entity.setDiag(diag::err_access_ctor);
+ AccessTarget AccessEntity(Context, AccessTarget::Member, NamingClass,
+ DeclAccessPair::make(Constructor, Access),
+ QualType());
+ switch (Entity.getKind()) {
+ default:
+ AccessEntity.setDiag(diag::err_access_ctor);
+ break;
+
+ case InitializedEntity::EK_Base:
+ AccessEntity.setDiag(PDiag(diag::err_access_ctor_base)
+ << Entity.getBaseSpecifier()->getType());
+ break;
+ }
- return CheckAccess(*this, UseLoc, Entity);
+ return CheckAccess(*this, UseLoc, AccessEntity);
}
/// Checks direct (i.e. non-inherited) access to an arbitrary class
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp
index a99f513609..fe7f79f9c5 100644
--- a/lib/Sema/SemaInit.cpp
+++ b/lib/Sema/SemaInit.cpp
@@ -3258,7 +3258,7 @@ static Sema::OwningExprResult CopyObject(Sema &S,
ASTOwningVector<&ActionBase::DeleteExpr> ConstructorArgs(S);
CurInit.release(); // Ownership transferred into MultiExprArg, below.
- S.CheckConstructorAccess(Loc, Constructor,
+ S.CheckConstructorAccess(Loc, Constructor, Entity,
Best->FoundDecl.getAccess());
if (IsExtraneousCopy) {
@@ -3521,7 +3521,7 @@ InitializationSequence::Perform(Sema &S,
if (CurInit.isInvalid())
return S.ExprError();
- S.CheckConstructorAccess(Kind.getLocation(), Constructor,
+ S.CheckConstructorAccess(Kind.getLocation(), Constructor, Entity,
FoundFn.getAccess());
CastKind = CastExpr::CK_ConstructorConversion;
@@ -3647,7 +3647,7 @@ InitializationSequence::Perform(Sema &S,
return S.ExprError();
// Only check access if all of that succeeded.
- S.CheckConstructorAccess(Loc, Constructor,
+ S.CheckConstructorAccess(Loc, Constructor, Entity,
Step->Function.FoundDecl.getAccess());
if (shouldBindAsTemporary(Entity))