Kaydet (Commit) f569c419 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Improve loplugin:revisibility

(for non-Windows--only code, as MSVC would complain about such cases anyway)

Change-Id: Id6daf61b79bd31529bdaeb7c6df4f354731ae7d7
üst f627c122
...@@ -41,11 +41,13 @@ bool ReVisibility::VisitFunctionDecl(FunctionDecl const * decl) { ...@@ -41,11 +41,13 @@ bool ReVisibility::VisitFunctionDecl(FunctionDecl const * decl) {
if (!ignoreLocation(decl) && hasExplicitVisibilityAttr(decl) if (!ignoreLocation(decl) && hasExplicitVisibilityAttr(decl)
&& !isFriendDecl(decl)) && !isFriendDecl(decl))
{ {
Decl const * first = nullptr;
for (Decl const * p = decl;;) { for (Decl const * p = decl;;) {
p = p->getPreviousDecl(); p = p->getPreviousDecl();
if (p == nullptr) { if (p == nullptr) {
break; break;
} }
first = p;
if (hasExplicitVisibilityAttr(p) && !isFriendDecl(p)) { if (hasExplicitVisibilityAttr(p) && !isFriendDecl(p)) {
report( report(
DiagnosticsEngine::Warning, DiagnosticsEngine::Warning,
...@@ -57,9 +59,25 @@ bool ReVisibility::VisitFunctionDecl(FunctionDecl const * decl) { ...@@ -57,9 +59,25 @@ bool ReVisibility::VisitFunctionDecl(FunctionDecl const * decl) {
"Previous visibility declaration is here", "Previous visibility declaration is here",
p->getAttr<VisibilityAttr>()->getLocation()) p->getAttr<VisibilityAttr>()->getLocation())
<< p->getAttr<VisibilityAttr>()->getRange(); << p->getAttr<VisibilityAttr>()->getRange();
break; return true;
} }
} }
if (decl->isThisDeclarationADefinition() && first != nullptr
&& !(compiler.getSourceManager().getFilename(
compiler.getSourceManager().getSpellingLoc(
decl->getLocation()))
.startswith(SRCDIR "/libreofficekit/")))
{
report(
DiagnosticsEngine::Warning,
"Visibility declaration on definition, not first declaration",
decl->getAttr<VisibilityAttr>()->getLocation())
<< decl->getAttr<VisibilityAttr>()->getRange();
report(
DiagnosticsEngine::Note, "First declaration is here",
first->getLocation())
<< first->getSourceRange();
}
} }
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment