summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-02-10 17:52:15 +0100
committerStephan Bergmann <sbergman@redhat.com>2017-02-10 17:52:15 +0100
commit07bcdbaed1427549e29af00107b99878b9a66a72 (patch)
tree04be4da08449ca6d140800023f9aee341ac046fa /compilerplugins
parent57a505e8e9f3fe655ad0d4e812be4fd3c102bcc1 (diff)
loplugin:dynexcspec: Deallocation functions are implicitly non-throwing
...so a dynamic exception specification should be replaced with noexcept(false). Doesn't look like this omission made any difference when running the rewriter across the LO code base earlier, though. Change-Id: Ib0e2b412b65cae7c1a68e875bbddf93f3656cebb
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/dynexcspec.cxx19
1 files changed, 16 insertions, 3 deletions
diff --git a/compilerplugins/clang/dynexcspec.cxx b/compilerplugins/clang/dynexcspec.cxx
index ee746461c06a..c3b8e79d0c78 100644
--- a/compilerplugins/clang/dynexcspec.cxx
+++ b/compilerplugins/clang/dynexcspec.cxx
@@ -29,6 +29,19 @@ bool isOverriding(FunctionDecl const * decl) {
&& m->begin_overridden_methods() != m->end_overridden_methods();
}
+bool isDtorOrDealloc(FunctionDecl const * decl) {
+ if (isa<CXXDestructorDecl>(decl)) {
+ return true;
+ }
+ switch (decl->getOverloadedOperator()) {
+ case OO_Delete:
+ case OO_Array_Delete:
+ return true;
+ default:
+ return false;
+ }
+}
+
class DynExcSpec:
public RecursiveASTVisitor<DynExcSpec>, public loplugin::RewritePlugin
{
@@ -75,13 +88,13 @@ public:
}
}
}
- bool dtor = isa<CXXDestructorDecl>(decl);
+ bool dtorOrDealloc = isDtorOrDealloc(decl);
SourceRange source;
#if CLANG_VERSION >= 40000
source = decl->getExceptionSpecSourceRange();
#endif
if (rewriter != nullptr && source.isValid()) {
- if (dtor) {
+ if (dtorOrDealloc) {
if (replaceText(source, "noexcept(false)")) {
return true;
}
@@ -125,7 +138,7 @@ public:
}
report(
DiagnosticsEngine::Warning,
- (dtor
+ (dtorOrDealloc
? "replace dynamic exception specification with 'noexcept(false)'"
: "remove dynamic exception specification"),
source.isValid() ? source.getBegin() : decl->getLocation())