[Libreoffice-commits] core.git: compilerplugins/clang

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Fri Nov 15 22:31:26 UTC 2019


 compilerplugins/clang/external.cxx      |   21 +++++++++++++++++++++
 compilerplugins/clang/test/external.cxx |   27 +++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

New commits:
commit d04eef858250f97690f32dba17f42d157a8767fc
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Fri Nov 15 16:16:21 2019 +0100
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Fri Nov 15 23:29:41 2019 +0100

    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 at redhat.com>

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 at +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 at +1 {{another declaration is here [loplugin:external]}}
+    friend void f2();
+};
+
+static void g()
+{
+    void f1();
+    // expected-note at +1 {{another declaration is here [loplugin:external]}}
+    void f2();
+}
+
+// expected-note at +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: */


More information about the Libreoffice-commits mailing list