From 4a6268f0d37f377181f972ed307d2a074e8e1b6a Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Thu, 19 Nov 2015 09:19:30 +0100 Subject: [PATCH] Adapt compilerplugins to old Clang versions Change-Id: I91335f1e81e251f0578792517dded9fae239fb61 --- compilerplugins/clang/compat.hxx | 9 +++++++++ compilerplugins/clang/typecheck.hxx | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/compilerplugins/clang/compat.hxx b/compilerplugins/clang/compat.hxx index 6b1451000ff6..0a16a3c99c2e 100644 --- a/compilerplugins/clang/compat.hxx +++ b/compilerplugins/clang/compat.hxx @@ -41,6 +41,15 @@ // Compatibility wrapper to abstract over (trivial) changes in the Clang API: namespace compat { +inline bool isLookupContext(clang::DeclContext const & ctxt) { +#if (__clang_major__ == 3 && __clang_minor__ > 7) || __clang_major__ > 3 + return ctxt.isLookupContext(); +#else + return !ctxt.isFunctionOrMethod() + && ctxt.getDeclKind() != clang::Decl::LinkageSpec; +#endif +} + inline bool isExternCContext(clang::DeclContext const & ctxt) { #if (__clang_major__ == 3 && __clang_minor__ >= 4) || __clang_major__ > 3 return ctxt.isExternCContext(); diff --git a/compilerplugins/clang/typecheck.hxx b/compilerplugins/clang/typecheck.hxx index 6ab8f74e1aad..35d4e5769b6e 100644 --- a/compilerplugins/clang/typecheck.hxx +++ b/compilerplugins/clang/typecheck.hxx @@ -12,11 +12,11 @@ #include -#include - #include #include +#include "compat.hxx" + namespace loplugin { class NamespaceCheck; @@ -72,7 +72,7 @@ public: TerminalCheck GlobalNamespace() const { return TerminalCheck( context_ != nullptr - && ((context_->isLookupContext() + && ((compat::isLookupContext(*context_) ? context_ : context_->getLookupParent()) ->isTranslationUnit())); }