Anders Carlsson | b9b485c | 2009-03-27 04:43:36 +0000 | [diff] [blame] | 1 | //===---- 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 Carlsson | ae9c08c | 2009-03-27 04:54:36 +0000 | [diff] [blame^] | 13 | |
| 14 | #include "Sema.h" |
| 15 | using namespace clang; |
| 16 | |
| 17 | bool 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 | } |