diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2019-11-15 16:16:21 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2019-11-15 23:29:41 +0100 |
commit | d04eef858250f97690f32dba17f42d157a8767fc (patch) | |
tree | 82dccfc772158b25e38a356fd0292a5e63e98e76 | |
parent | 1a137ef35d67a4aff7b2a6f1d3aa3c944c7a0b41 (diff) |
loplugin:external: Don't warn for injected friend functions
Change-Id: I35c0930f6ab8ae5d96e433958cf29791c78d5e31
Reviewed-on: https://gerrit.libreoffice.org/82802
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r-- | compilerplugins/clang/external.cxx | 21 | ||||
-rw-r--r-- | compilerplugins/clang/test/external.cxx | 27 |
2 files changed, 48 insertions, 0 deletions
diff --git a/compilerplugins/clang/external.cxx b/compilerplugins/clang/external.cxx index 3248df5db078..2b6b689ea315 100644 --- a/compilerplugins/clang/external.cxx +++ b/compilerplugins/clang/external.cxx @@ -32,6 +32,19 @@ bool derivesFromTestFixture(CXXRecordDecl const* decl) || std::any_of(decl->vbases_begin(), decl->vbases_end(), pred); } +bool isInjectedFunction(FunctionDecl const* decl) +{ + for (auto d = decl->redecls_begin(); d != decl->redecls_end(); ++d) + { + auto const c = d->getLexicalDeclContext(); + if (!(c->isFunctionOrMethod() || c->isRecord())) + { + return false; + } + } + return true; +} + class External : public loplugin::FilteringPlugin<External> { public: @@ -146,6 +159,10 @@ public: // #pragma GCC diagnostic ignored "-Wunused-function" return true; } + if (isInjectedFunction(decl)) + { + return true; + } return handleDeclaration(decl); } @@ -195,6 +212,10 @@ public: { return true; } + if (isInjectedFunction(decl->getTemplatedDecl())) + { + return true; + } return handleDeclaration(decl); } diff --git a/compilerplugins/clang/test/external.cxx b/compilerplugins/clang/test/external.cxx index fd7d558efc09..ff996f54a467 100644 --- a/compilerplugins/clang/test/external.cxx +++ b/compilerplugins/clang/test/external.cxx @@ -16,10 +16,37 @@ int const n2 = 0; // no warning, internal linkage constexpr int n3 = 0; // no warning, internal linkage +struct S1 +{ + friend void f1() {} // no warning for injected function (no place where to mark it `static`) + template <typename> friend void ft1() {} // ...nor for injected function template + // expected-error@+1 {{externally available entity 'f2' is not previously declared in an included file (if it is only used in this translation unit, make it static; otherwise, provide a declaration of it in an included file) [loplugin:external]}} + friend void f2() {} +}; + +struct S2 +{ + friend void f1(); + template <typename> friend void ft1(); + // expected-note@+1 {{another declaration is here [loplugin:external]}} + friend void f2(); +}; + +static void g() +{ + void f1(); + // expected-note@+1 {{another declaration is here [loplugin:external]}} + void f2(); +} + +// expected-note@+1 {{another declaration is here [loplugin:external]}} +void f2(); + int main() { (void)n2; (void)n3; + g(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |