Anders Carlsson | 9aa0412 | 2009-03-27 05:05:05 +0000 | [diff] [blame^] | 1 | //===---- SemaAccess.cpp - C++ Access Control -------------------*- C++ -*-===// |
Anders Carlsson | b9b485c | 2009-03-27 04:43:36 +0000 | [diff] [blame] | 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 | |
Anders Carlsson | 9aa0412 | 2009-03-27 05:05:05 +0000 | [diff] [blame^] | 17 | /// SetMemberAccessSpecifier - Set the access specifier of a member. |
| 18 | /// Returns true on error (when the previous member decl access specifier |
| 19 | /// is different from the new member decl access specifier). |
Anders Carlsson | ae9c08c | 2009-03-27 04:54:36 +0000 | [diff] [blame] | 20 | bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl, |
| 21 | NamedDecl *PrevMemberDecl, |
| 22 | AccessSpecifier LexicalAS) { |
| 23 | if (!PrevMemberDecl) { |
| 24 | // Use the lexical access specifier. |
| 25 | MemberDecl->setAccess(LexicalAS); |
| 26 | return false; |
| 27 | } |
| 28 | |
| 29 | // C++ [class.access.spec]p3: When a member is redeclared its access |
| 30 | // specifier must be same as its initial declaration. |
| 31 | if (LexicalAS != AS_none && LexicalAS != PrevMemberDecl->getAccess()) { |
| 32 | Diag(MemberDecl->getLocation(), |
| 33 | diag::err_class_redeclared_with_different_access) |
| 34 | << MemberDecl << LexicalAS; |
| 35 | Diag(PrevMemberDecl->getLocation(), diag::note_previous_access_declaration) |
| 36 | << PrevMemberDecl << PrevMemberDecl->getAccess(); |
| 37 | return true; |
| 38 | } |
| 39 | |
| 40 | MemberDecl->setAccess(PrevMemberDecl->getAccess()); |
| 41 | return false; |
| 42 | } |
Anders Carlsson | 9aa0412 | 2009-03-27 05:05:05 +0000 | [diff] [blame^] | 43 | |
| 44 | /// CheckBaseClassAccess - Check that a derived class can access its base class |
| 45 | /// and report an error if it can't. [class.access.base] |
| 46 | bool Sema::CheckBaseClassAccess(QualType Derived, QualType Base, |
| 47 | BasePaths& Paths, SourceLocation AccessLoc) { |
| 48 | return false; |
| 49 | } |