summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/AST/DeclBase.h18
-rw-r--r--clang/lib/AST/DeclBase.cpp8
-rw-r--r--clang/lib/Sema/SemaDecl.cpp4
-rw-r--r--clang/test/SemaCXX/nested-name-spec.cpp1
4 files changed, 25 insertions, 6 deletions
diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h
index a53b459c990..5ee607b88e5 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -138,6 +138,12 @@ private:
/// the implementation rather than explicitly written by the user.
bool Implicit : 1;
+#ifndef NDEBUG
+ void CheckAccessDeclContext() const;
+#else
+ void CheckAccessDeclContext() const { }
+#endif
+
protected:
/// Access - Used by C++ decls for the access specifier.
// NOTE: VC++ treats enums as signed, avoid using the AccessSpecifier enum
@@ -148,7 +154,7 @@ protected:
: NextDeclarator(0), NextDeclInScope(0),
DeclCtx(reinterpret_cast<uintptr_t>(DC)),
Loc(L), DeclKind(DK), InvalidDecl(0),
- HasAttrs(false), Implicit(false) {
+ HasAttrs(false), Implicit(false), Access(AS_none) {
if (Decl::CollectingStats()) addDeclKind(DK);
}
@@ -175,11 +181,15 @@ public:
const_cast<const Decl*>(this)->getDeclContext());
}
- void setAccess(AccessSpecifier AS) {
- assert(AS != AS_none && "Can't set access to none");
+ void setAccess(AccessSpecifier AS) {
Access = AS;
+ CheckAccessDeclContext();
+ }
+
+ AccessSpecifier getAccess() const {
+ CheckAccessDeclContext();
+ return AccessSpecifier(Access);
}
- AccessSpecifier getAccess() const { return AccessSpecifier(Access); }
bool hasAttrs() const { return HasAttrs; }
void addAttr(Attr *attr);
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 812c362acd3..cb126184435 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -272,6 +272,14 @@ DeclContext *Decl::castToDeclContext(const Decl *D) {
}
}
+#ifndef NDEBUG
+void Decl::CheckAccessDeclContext() const {
+ assert((Access != AS_none || !isa<CXXRecordDecl>(getDeclContext())) &&
+ "Access specifier is AS_none inside a record decl");
+}
+
+#endif
+
//===----------------------------------------------------------------------===//
// DeclContext Implementation
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 220113734f0..835792ee2db 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3384,7 +3384,9 @@ CreateNewDecl:
// lexical context will be different from the semantic context.
New->setLexicalDeclContext(CurContext);
- if (AS != AS_none)
+ if (PrevDecl)
+ New->setAccess(PrevDecl->getAccess());
+ else
New->setAccess(AS);
if (TK == TK_Definition)
diff --git a/clang/test/SemaCXX/nested-name-spec.cpp b/clang/test/SemaCXX/nested-name-spec.cpp
index f575fb82b41..07fd5a9bf85 100644
--- a/clang/test/SemaCXX/nested-name-spec.cpp
+++ b/clang/test/SemaCXX/nested-name-spec.cpp
@@ -170,4 +170,3 @@ Y::foo y; // expected-error{{incomplete type 'struct Y' named in nested name spe
X::X() : a(5) { } // expected-error{{use of undeclared identifier 'X'}} \
// expected-error{{C++ requires a type specifier for all declarations}} \
// expected-error{{only constructors take base initializers}}
-
OpenPOWER on IntegriCloud