aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/AST/DeclCXX.h5
-rw-r--r--include/clang/Basic/Diagnostic.h3
-rw-r--r--lib/AST/DeclCXX.cpp21
-rw-r--r--lib/Sema/SemaDeclCXX.cpp19
4 files changed, 30 insertions, 18 deletions
diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h
index e1f1095d3d..940d95ca43 100644
--- a/include/clang/AST/DeclCXX.h
+++ b/include/clang/AST/DeclCXX.h
@@ -980,6 +980,11 @@ public:
}
static bool classof(StaticAssertDecl *D) { return true; }
};
+
+/// Insertion operator for diagnostics. This allows sending AccessSpecifier's
+/// into a diagnostic with <<.
+const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
+ AccessSpecifier AS);
} // end namespace clang
diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h
index a9f87107ab..c6c9e394f5 100644
--- a/include/clang/Basic/Diagnostic.h
+++ b/include/clang/Basic/Diagnostic.h
@@ -144,7 +144,8 @@ public:
ak_identifierinfo, // IdentifierInfo
ak_qualtype, // QualType
ak_declarationname, // DeclarationName
- ak_nameddecl // NamedDecl *
+ ak_nameddecl, // NamedDecl *
+ ak_accessspecifier // AccessSpecifier
};
private:
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp
index 98d7d8f487..7c5dbced31 100644
--- a/lib/AST/DeclCXX.cpp
+++ b/lib/AST/DeclCXX.cpp
@@ -377,3 +377,24 @@ void StaticAssertDecl::Destroy(ASTContext& C) {
StaticAssertDecl::~StaticAssertDecl() {
}
+static const char *getAccessName(AccessSpecifier AS) {
+ switch (AS) {
+ default:
+ case AS_none:
+ assert("Invalid access specifier!");
+ return 0;
+ case AS_public:
+ return "public";
+ case AS_private:
+ return "private";
+ case AS_protected:
+ return "protected";
+ }
+}
+
+const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB,
+ AccessSpecifier AS) {
+ return DB << getAccessName(AS);
+}
+
+
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 11ab071c58..cb44cfc186 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -2530,21 +2530,6 @@ void Sema::SetDeclDeleted(DeclTy *dcl, SourceLocation DelLoc) {
Fn->setDeleted();
}
-static const char *getAccessName(AccessSpecifier AS) {
- switch (AS) {
- default:
- case AS_none:
- assert("Invalid access specifier!");
- return 0;
- case AS_public:
- return "public";
- case AS_private:
- return "private";
- case AS_protected:
- return "protected";
- }
-}
-
bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl,
NamedDecl *PrevMemberDecl,
AccessSpecifier LexicalAS) {
@@ -2559,9 +2544,9 @@ bool Sema::SetMemberAccessSpecifier(NamedDecl *MemberDecl,
if (LexicalAS != AS_none && LexicalAS != PrevMemberDecl->getAccess()) {
Diag(MemberDecl->getLocation(),
diag::err_class_redeclared_with_different_access)
- << MemberDecl << getAccessName(LexicalAS);
+ << MemberDecl << LexicalAS;
Diag(PrevMemberDecl->getLocation(), diag::note_previous_access_declaration)
- << PrevMemberDecl << getAccessName(PrevMemberDecl->getAccess());
+ << PrevMemberDecl << PrevMemberDecl->getAccess();
return true;
}