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

Wastack btomi96 at gmail.com
Fri Apr 1 06:47:29 UTC 2016


 compilerplugins/clang/staticanonymous.cxx |   67 ++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

New commits:
commit e097e419ee5c47239262a16526f4e37775fb2004
Author: Wastack <btomi96 at gmail.com>
Date:   Thu Mar 31 08:49:20 2016 +0200

    tdf#97966 Compiler plugin
    
    Warns about redundant 'static' keywords in unnamed namespace.
    
    Change-Id: Iecab69161e24d73e39a8dd5baaba6929e12d4f29
    Reviewed-on: https://gerrit.libreoffice.org/23679
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/compilerplugins/clang/staticanonymous.cxx b/compilerplugins/clang/staticanonymous.cxx
new file mode 100644
index 0000000..da5724b
--- /dev/null
+++ b/compilerplugins/clang/staticanonymous.cxx
@@ -0,0 +1,67 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * Based on LLVM/Clang.
+ *
+ */
+#include "plugin.hxx"
+#include "compat.hxx"
+/*
+This is a compile check.
+
+Warns about functions with static keyword in an unnamed namespace.
+*/
+
+namespace loplugin
+{
+
+class StaticAnonymous
+    : public RecursiveASTVisitor< StaticAnonymous >
+    , public Plugin
+    {
+    public:
+        StaticAnonymous( const InstantiationData& data );
+        virtual void run() override;
+        bool VisitFunctionDecl( FunctionDecl* func );
+
+    };
+
+StaticAnonymous::StaticAnonymous( const InstantiationData& data )
+    : Plugin( data )
+    {
+    }
+
+void StaticAnonymous::run()
+    {
+    TraverseDecl( compiler.getASTContext().getTranslationUnitDecl());
+    }
+
+
+bool StaticAnonymous::VisitFunctionDecl( FunctionDecl* func )
+
+    {
+    if( ignoreLocation( func ) )
+        return true;
+    if( func -> isInAnonymousNamespace () )
+    {
+      if ( !isa<CXXMethodDecl>(func) && !compat::isInExternCContext(*func) )
+         {
+            if(func-> getStorageClass() == SC_Static)
+               {
+                    report( DiagnosticsEngine::Warning,
+                        "redundant 'static' keyword in unnamed namespace",
+                        func->getLocStart());
+               }
+         }
+    }
+
+    return true;
+    }
+
+// Register the plugin action with the LO plugin handling.
+static Plugin::Registration< StaticAnonymous > X( "staticanonymous",true);
+
+} // namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list