blob: 2ac9a539f3e9a5a2a02f4d76b3c91b12d987276c [file] [log] [blame]
Anders Carlssonb9b485c2009-03-27 04:43:36 +00001//===---- SemaInherit.cpp - C++ Access Control ------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file provides Sema routines for C++ access control semantics.
11//
12//===----------------------------------------------------------------------===//
Anders Carlssonae9c08c2009-03-27 04:54:36 +000013
14#include "Sema.h"
15using namespace clang;
16
17bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl,
18 NamedDecl *PrevMemberDecl,
19 AccessSpecifier LexicalAS) {
20 if (!PrevMemberDecl) {
21 // Use the lexical access specifier.
22 MemberDecl->setAccess(LexicalAS);
23 return false;
24 }
25
26 // C++ [class.access.spec]p3: When a member is redeclared its access
27 // specifier must be same as its initial declaration.
28 if (LexicalAS != AS_none && LexicalAS != PrevMemberDecl->getAccess()) {
29 Diag(MemberDecl->getLocation(),
30 diag::err_class_redeclared_with_different_access)
31 << MemberDecl << LexicalAS;
32 Diag(PrevMemberDecl->getLocation(), diag::note_previous_access_declaration)
33 << PrevMemberDecl << PrevMemberDecl->getAccess();
34 return true;
35 }
36
37 MemberDecl->setAccess(PrevMemberDecl->getAccess());
38 return false;
39}