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

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Mon May 3 09:24:15 UTC 2021


 compilerplugins/clang/noexcept.cxx           |   82 +++++++++++++++++++++++++++
 compilerplugins/clang/test/noexcept.cxx      |   16 +++++
 solenv/CompilerTest_compilerplugins_clang.mk |    1 
 3 files changed, 99 insertions(+)

New commits:
commit 0d18b90b75c074c0cca4d12a6468f2397909b886
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Thu Apr 29 12:00:25 2021 +0200
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Mon May 3 11:23:34 2021 +0200

    throw() -> noexcept, part 3/3: New loplugin:noexcept
    
    Change-Id: I3ce3fab3e8047be14e003f1f3096b4e2745534e9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115026
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/compilerplugins/clang/noexcept.cxx b/compilerplugins/clang/noexcept.cxx
new file mode 100644
index 000000000000..ae0bfdf95207
--- /dev/null
+++ b/compilerplugins/clang/noexcept.cxx
@@ -0,0 +1,82 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "plugin.hxx"
+
+namespace
+{
+class Noexcept : public loplugin::FilteringRewritePlugin<Noexcept>
+{
+public:
+    explicit Noexcept(loplugin::InstantiationData const& data)
+        : FilteringRewritePlugin(data)
+    {
+    }
+
+    void run() override
+    {
+        // Don't execute for < C++11, so we don't accidentally rewrite the legacy definitions of
+        // SAL_THROW_EXTERN_C and SAL_NOEXCEPT in include/sal/types.h e.g. when building
+        // CppunitTest_odk_checkapi which explicitly uses gb_CXX03FLAGS:
+        if (compiler.getLangOpts().CPlusPlus11)
+        {
+            TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
+        }
+    }
+
+    bool VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc tloc)
+    {
+        if (ignoreLocation(tloc))
+        {
+            return true;
+        }
+        if (tloc.getTypePtr()->getExceptionSpecType() != EST_DynamicNone)
+        {
+            return true;
+        }
+        auto const r = tloc.getExceptionSpecRange();
+        auto const repl = isInUnoIncludeFile(r.getBegin()) ? "SAL_NOEXCEPT" : "noexcept";
+        if (rewriter != nullptr)
+        {
+            auto r2 = r;
+            auto l1 = r.getBegin();
+            while (compiler.getSourceManager().isMacroArgExpansion(l1))
+            {
+                l1 = compiler.getSourceManager().getImmediateMacroCallerLoc(l1);
+            }
+            if (compiler.getSourceManager().isMacroBodyExpansion(l1))
+            {
+                auto l2 = r.getEnd();
+                while (compiler.getSourceManager().isMacroArgExpansion(l2))
+                {
+                    l2 = compiler.getSourceManager().getImmediateMacroCallerLoc(l2);
+                }
+                if (compiler.getSourceManager().isMacroBodyExpansion(l2))
+                {
+                    //TODO: check l1, l2 are in same macro body expansion
+                    r2 = { compiler.getSourceManager().getSpellingLoc(l1),
+                           compiler.getSourceManager().getSpellingLoc(l2) };
+                }
+            }
+            if (replaceText(r2, repl))
+            {
+                return true;
+            }
+        }
+        report(DiagnosticsEngine::Warning,
+               "Replace legacy dynamic 'throw ()' exception specification with '%0'", r.getBegin())
+            << repl << r;
+        return true;
+    }
+};
+
+loplugin::Plugin::Registration<Noexcept> X("noexcept", true);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/compilerplugins/clang/test/noexcept.cxx b/compilerplugins/clang/test/noexcept.cxx
new file mode 100644
index 000000000000..f46a3d87f2b7
--- /dev/null
+++ b/compilerplugins/clang/test/noexcept.cxx
@@ -0,0 +1,16 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+// expected-error at +1 {{Replace legacy dynamic 'throw ()' exception specification with 'noexcept' [loplugin:noexcept]}}
+void f() throw();
+
+// expected-error at +1 {{Replace legacy dynamic 'throw ()' exception specification with 'noexcept' [loplugin:noexcept]}}
+using F = void() throw();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/solenv/CompilerTest_compilerplugins_clang.mk b/solenv/CompilerTest_compilerplugins_clang.mk
index 6ac27d98d4cf..3a05e8fb2bb3 100644
--- a/solenv/CompilerTest_compilerplugins_clang.mk
+++ b/solenv/CompilerTest_compilerplugins_clang.mk
@@ -49,6 +49,7 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \
     compilerplugins/clang/test/mapindex \
     compilerplugins/clang/test/makeshared \
     compilerplugins/clang/test/namespaceindentation \
+    compilerplugins/clang/test/noexcept \
     compilerplugins/clang/test/noexceptmove \
     compilerplugins/clang/test/nullptr \
     compilerplugins/clang/test/oncevar \


More information about the Libreoffice-commits mailing list