Kaydet (Commit) 07bcdbae authored tarafından Stephan Bergmann's avatar Stephan Bergmann

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
üst 57a505e8
...@@ -29,6 +29,19 @@ bool isOverriding(FunctionDecl const * decl) { ...@@ -29,6 +29,19 @@ bool isOverriding(FunctionDecl const * decl) {
&& m->begin_overridden_methods() != m->end_overridden_methods(); && 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: class DynExcSpec:
public RecursiveASTVisitor<DynExcSpec>, public loplugin::RewritePlugin public RecursiveASTVisitor<DynExcSpec>, public loplugin::RewritePlugin
{ {
...@@ -75,13 +88,13 @@ public: ...@@ -75,13 +88,13 @@ public:
} }
} }
} }
bool dtor = isa<CXXDestructorDecl>(decl); bool dtorOrDealloc = isDtorOrDealloc(decl);
SourceRange source; SourceRange source;
#if CLANG_VERSION >= 40000 #if CLANG_VERSION >= 40000
source = decl->getExceptionSpecSourceRange(); source = decl->getExceptionSpecSourceRange();
#endif #endif
if (rewriter != nullptr && source.isValid()) { if (rewriter != nullptr && source.isValid()) {
if (dtor) { if (dtorOrDealloc) {
if (replaceText(source, "noexcept(false)")) { if (replaceText(source, "noexcept(false)")) {
return true; return true;
} }
...@@ -125,7 +138,7 @@ public: ...@@ -125,7 +138,7 @@ public:
} }
report( report(
DiagnosticsEngine::Warning, DiagnosticsEngine::Warning,
(dtor (dtorOrDealloc
? "replace dynamic exception specification with 'noexcept(false)'" ? "replace dynamic exception specification with 'noexcept(false)'"
: "remove dynamic exception specification"), : "remove dynamic exception specification"),
source.isValid() ? source.getBegin() : decl->getLocation()) source.isValid() ? source.getBegin() : decl->getLocation())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment