aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-03-26 01:19:02 +0000
committerAnders Carlsson <andersca@mac.com>2009-03-26 01:19:02 +0000
commit0cf8830a45115176ef5ba5416b7ad7aa9d5cb255 (patch)
treef183a6590a8d94d43d04682ea0dfb35422e99469
parent5aeccdbb4bdc94e48c04cacc59fa812af32109b2 (diff)
Factor the member access specifier setting code into its own function. No intended functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67725 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/Sema.h7
-rw-r--r--lib/Sema/SemaDecl.cpp29
-rw-r--r--lib/Sema/SemaDeclCXX.cpp40
3 files changed, 49 insertions, 27 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 7f2f109734..9d71cf3229 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -1616,6 +1616,13 @@ public:
FunctionDecl::StorageClass& SC);
DeclTy *ActOnConversionDeclarator(CXXConversionDecl *Conversion);
+ /// SetMemberAccessSpecifier - Set the access specifier of a member.
+ /// Returns true on error (when the previous member decl access specifier
+ /// is different from the new member decl access specifier).
+ bool SetMemberAccessSpecifier(NamedDecl *MemberDecl,
+ NamedDecl *PrevMemberDecl,
+ AccessSpecifier LexicalAS);
+
//===--------------------------------------------------------------------===//
// C++ Derived Classes
//
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index d974301785..e9f586583c 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -3083,21 +3083,6 @@ TypedefDecl *Sema::ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
return NewTD;
}
-static const char *getAccessName(AccessSpecifier AS) {
- switch (AS) {
- default:
- case AS_none:
- assert("Invalid access specifier!");
- return 0;
- case AS_public:
- return "public";
- case AS_private:
- return "private";
- case AS_protected:
- return "protected";
- }
-}
-
/// ActOnTag - This is invoked when we see 'struct foo' or 'struct {'. In the
/// former case, Name will be non-null. In the later case, Name will be null.
/// TagSpec indicates what kind of tag this is. TK indicates whether this is a
@@ -3399,18 +3384,8 @@ CreateNewDecl:
// lexical context will be different from the semantic context.
New->setLexicalDeclContext(CurContext);
- if (PrevDecl) {
- // C++ [class.access.spec]p3: When a member is redeclared its access
- // specifier must be same as its initial declaration.
- if (AS != AS_none && AS != PrevDecl->getAccess()) {
- Diag(Loc, diag::err_class_redeclared_with_different_access)
- << New << getAccessName(AS);
- Diag(PrevDecl->getLocation(), diag::note_previous_access_declaration)
- << PrevDecl << getAccessName(PrevDecl->getAccess());
- } else
- New->setAccess(PrevDecl->getAccess());
- } else
- New->setAccess(AS);
+ // Set the access specifier.
+ SetMemberAccessSpecifier(New, PrevDecl, AS);
if (TK == TK_Definition)
New->startDefinition();
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index d734ffe5cf..11ab071c58 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -2529,3 +2529,43 @@ void Sema::SetDeclDeleted(DeclTy *dcl, SourceLocation DelLoc) {
}
Fn->setDeleted();
}
+
+static const char *getAccessName(AccessSpecifier AS) {
+ switch (AS) {
+ default:
+ case AS_none:
+ assert("Invalid access specifier!");
+ return 0;
+ case AS_public:
+ return "public";
+ case AS_private:
+ return "private";
+ case AS_protected:
+ return "protected";
+ }
+}
+
+bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl,
+ NamedDecl *PrevMemberDecl,
+ AccessSpecifier LexicalAS) {
+ if (!PrevMemberDecl) {
+ // Use the lexical access specifier.
+ MemberDecl->setAccess(LexicalAS);
+ return false;
+ }
+
+ // C++ [class.access.spec]p3: When a member is redeclared its access
+ // specifier must be same as its initial declaration.
+ if (LexicalAS != AS_none && LexicalAS != PrevMemberDecl->getAccess()) {
+ Diag(MemberDecl->getLocation(),
+ diag::err_class_redeclared_with_different_access)
+ << MemberDecl << getAccessName(LexicalAS);
+ Diag(PrevMemberDecl->getLocation(), diag::note_previous_access_declaration)
+ << PrevMemberDecl << getAccessName(PrevMemberDecl->getAccess());
+ return true;
+ }
+
+ MemberDecl->setAccess(PrevMemberDecl->getAccess());
+ return false;
+}
+