diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2019-11-15 12:59:31 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2019-11-15 17:55:00 +0100 |
commit | ef57b9cd3c4c37fe70b7bc89361393f6f8b36d07 (patch) | |
tree | 7864540c28d18a4ed6efc449478992e636b5cd25 | |
parent | 1872b44c9a2ee2bd00be54c6c310b72579d7a47f (diff) |
loplugin:external: Note all other declarations of the same entity
...not just those that came before
Change-Id: Ib10ca34cb2ee63124999d56bb00d94f000f33ea1
Reviewed-on: https://gerrit.libreoffice.org/82782
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r-- | compilerplugins/clang/external.cxx | 8 | ||||
-rw-r--r-- | compilerplugins/clang/test/external.cxx | 2 |
2 files changed, 8 insertions, 2 deletions
diff --git a/compilerplugins/clang/external.cxx b/compilerplugins/clang/external.cxx index fe4328c1187b..442d174bd15b 100644 --- a/compilerplugins/clang/external.cxx +++ b/compilerplugins/clang/external.cxx @@ -295,9 +295,13 @@ private: decl->getLocation()) << (typedefed != nullptr) << (typedefed == nullptr ? decl : typedefed) << canStatic << (canStatic && canUnnamed) << canUnnamed << decl->getSourceRange(); - for (auto d = decl->getPreviousDecl(); d != nullptr; d = d->getPreviousDecl()) + for (auto d = decl->redecls_begin(); d != decl->redecls_end(); ++d) { - report(DiagnosticsEngine::Note, "previous declaration is here", d->getLocation()) + if (*d == decl) + { + continue; + } + report(DiagnosticsEngine::Note, "another declaration is here", d->getLocation()) << d->getSourceRange(); } //TODO: Class template specializations can be in the enclosing namespace, so no need to diff --git a/compilerplugins/clang/test/external.cxx b/compilerplugins/clang/test/external.cxx index f4f3d770f09d..fd7d558efc09 100644 --- a/compilerplugins/clang/test/external.cxx +++ b/compilerplugins/clang/test/external.cxx @@ -9,6 +9,8 @@ // expected-error@+1 {{externally available entity 'n1' is not previously declared in an included file (if it is only used in this translation unit, make it static or put it in an unnamed namespace; otherwise, provide a declaration of it in an included file) [loplugin:external]}} int n1 = 0; +// expected-note@+1 {{another declaration is here [loplugin:external]}} +extern int n1; int const n2 = 0; // no warning, internal linkage |