diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2014-04-01 19:18:35 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2014-04-01 19:22:54 +0200 |
commit | 362d4f0cd4e50111edfae9d30c90602c37ed65a2 (patch) | |
tree | 0b432c049d580dcac6130bca9fb028bab8af8fa8 /compilerplugins | |
parent | b66d87086804460c1986df1b832fd6b2ea075a90 (diff) |
Explicitly mark overriding destructors as "virtual"
It appears that the C++ standard allows overriding destructors to be marked
"override," but at least some MSVC versions complain about it, so at least make
sure such destructors are explicitly marked "virtual."
Change-Id: I0e1cafa7584fd16ebdce61f569eae2373a71b0a1
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/saloverride.cxx | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/compilerplugins/clang/saloverride.cxx b/compilerplugins/clang/saloverride.cxx index f37e915ea76e..6b62fb3e0322 100644 --- a/compilerplugins/clang/saloverride.cxx +++ b/compilerplugins/clang/saloverride.cxx @@ -40,13 +40,31 @@ bool SalOverride::VisitCXXMethodDecl(CXXMethodDecl const * decl) { // external QtCore/qobjectdefs.h: if (ignoreLocation(decl) || !compat::isFirstDecl(*decl) || decl->begin_overridden_methods() == decl->end_overridden_methods() - || decl->hasAttr<OverrideAttr>() || isa<CXXDestructorDecl>(decl) + || decl->hasAttr<OverrideAttr>() || ignoreLocation( compiler.getSourceManager().getSpellingLoc( decl->getNameInfo().getLoc()))) { return true; } + // It appears that the C++ standard allows overriding destructors to be + // marked "override," but at least some MSVC versions complain about it, so + // at least make sure such destructors are explicitly marked "virtual": + if (isa<CXXDestructorDecl>(decl)) { + if (!decl->isVirtualAsWritten() + && (rewriter == nullptr + || !insertTextBefore( + decl->getSourceRange().getBegin(), "virtual "))) + { + report( + DiagnosticsEngine::Warning, + ("overriding destructor declaration not explicitly marked" + " 'virtual'"), + decl->getLocation()) + << decl->getSourceRange(); + } + return true; + } #if LO_COMPILERPLUGINS_CLANG_COMPAT_HAVE_isAtEndOfImmediateMacroExpansion if (rewriter != nullptr) { // In void MACRO(...); getSourceRange().getEnd() would (erroneously?) |