diff options
author | hans@chromium.org <hans@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-25 13:05:31 +0000 |
---|---|---|
committer | hans@chromium.org <hans@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-25 13:05:31 +0000 |
commit | 8918bad8309e2667d82cf17142309e10e45641ae (patch) | |
tree | c077e5a5eb13c595fc25e367d202a9e91d302784 /tools/clang/plugins | |
parent | 62c005f8d74abad9e2a938f117fbb4e862a003a1 (diff) | |
download | chromium_src-8918bad8309e2667d82cf17142309e10e45641ae.zip chromium_src-8918bad8309e2667d82cf17142309e10e45641ae.tar.gz chromium_src-8918bad8309e2667d82cf17142309e10e45641ae.tar.bz2 |
Clang style-check plugin: check for virtual keyword on virtual dtors.
BUG=83408
TEST=none
Review URL: http://codereview.chromium.org/7065027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86604 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/clang/plugins')
-rw-r--r-- | tools/clang/plugins/FindBadConstructs.cpp | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/tools/clang/plugins/FindBadConstructs.cpp b/tools/clang/plugins/FindBadConstructs.cpp index e90c280..e79b311 100644 --- a/tools/clang/plugins/FindBadConstructs.cpp +++ b/tools/clang/plugins/FindBadConstructs.cpp @@ -136,6 +136,27 @@ class FindBadConstructsConsumer : public ChromeClassTester { } } + void CheckVirtualMethod(const CXXMethodDecl *method) { + SourceLocation loc = method->getTypeSpecStartLoc(); + if (isa<CXXDestructorDecl>(method)) + loc = method->getInnerLocStart(); + + if (method->isVirtual() && !method->isVirtualAsWritten()) + emitWarning(loc, "Overridden method must have \"virtual\" keyword."); + + // Virtual methods should not have inline definitions beyond "{}". + if (method->isVirtual() && method->hasBody() && method->hasInlineBody()) { + if (CompoundStmt* cs = dyn_cast<CompoundStmt>(method->getBody())) { + if (cs->size()) { + emitWarning( + cs->getLBracLoc(), + "virtual methods with non-empty bodies shouldn't be " + "declared inline."); + } + } + } + } + // Makes sure there is a "virtual" keyword on virtual methods and that there // are no inline function bodies on them (but "{}" is allowed). // @@ -162,28 +183,11 @@ class FindBadConstructsConsumer : public ChromeClassTester { if (it->isCopyAssignmentOperator() || dyn_cast<CXXConstructorDecl>(*it)) { // Ignore constructors and assignment operators. - } else if (dyn_cast<CXXDestructorDecl>(*it)) { - // TODO: I'd love to handle this case, but - // CXXDestructorDecl::isImplicitlyDefined() asserts if I call it - // here, and against my better judgment, I don't want to *always* - // disallow implicit destructors. + } else if (dyn_cast<CXXDestructorDecl>(*it) && + !record->hasUserDeclaredDestructor()) { + // Ignore non-userdeclared destructors. } else { - if (it->isVirtual() && !it->isVirtualAsWritten()) { - emitWarning(it->getTypeSpecStartLoc(), - "Overridden method must have \"virtual\" keyword."); - } - - // Virtual methods should not have inline definitions beyond "{}". - if (it->isVirtual() && it->hasBody() && it->hasInlineBody()) { - if (CompoundStmt* cs = dyn_cast<CompoundStmt>(it->getBody())) { - if (cs->size()) { - emitWarning( - cs->getLBracLoc(), - "virtual methods with non-empty bodies shouldn't be " - "declared inline."); - } - } - } + CheckVirtualMethod(*it); } } } |