SemaAccess.cpp revision c60e88819a273d54faa71a2cd6c3d79dd48c12e0
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//===----------------------------------------------------------------------===//
13
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}
40