summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/cpp11-migrate/AddOverride/AddOverrideActions.cpp
diff options
context:
space:
mode:
authorEdwin Vane <edwin.vane@intel.com>2013-05-10 14:04:58 +0000
committerEdwin Vane <edwin.vane@intel.com>2013-05-10 14:04:58 +0000
commitb8c38756180df345534d4c816f648a9d74760f42 (patch)
treef1e202458b7722d4d54c9ce2825be86d3e2997d1 /clang-tools-extra/cpp11-migrate/AddOverride/AddOverrideActions.cpp
parent66e4f83c072b9dc552f35cf31add92d9f382feba (diff)
downloadbcm5719-llvm-b8c38756180df345534d4c816f648a9d74760f42.tar.gz
bcm5719-llvm-b8c38756180df345534d4c816f648a9d74760f42.zip
cpp11-migrate: Fix crash in AddOverride due to template instantiations
This patch fixes different issues: - override is not added in template 'contexts' (this will be further improved to handle safe situations, a test for this has been written already) - the main file is now checked before the modifications are applied - override is not applied now when dealing with pure methods since it was misplaced (ignoring it isn't the perfect solution but it seems difficult to find the location just before the pure-specifier) Fixes PR15827 Author: Guillaume Papin <guillaume.papin@epitech.eu> llvm-svn: 181596
Diffstat (limited to 'clang-tools-extra/cpp11-migrate/AddOverride/AddOverrideActions.cpp')
-rw-r--r--clang-tools-extra/cpp11-migrate/AddOverride/AddOverrideActions.cpp56
1 files changed, 34 insertions, 22 deletions
diff --git a/clang-tools-extra/cpp11-migrate/AddOverride/AddOverrideActions.cpp b/clang-tools-extra/cpp11-migrate/AddOverride/AddOverrideActions.cpp
index 3d1f1ff8c13..197befa4f4f 100644
--- a/clang-tools-extra/cpp11-migrate/AddOverride/AddOverrideActions.cpp
+++ b/clang-tools-extra/cpp11-migrate/AddOverride/AddOverrideActions.cpp
@@ -36,28 +36,40 @@ void AddOverrideFixer::run(const MatchFinder::MatchResult &Result) {
if (!SM.isFromMainFile(M->getLocStart()))
return;
+ if (!SM.isFromMainFile(M->getLocStart()))
+ return;
+
// First check that there isn't already an override attribute.
- if (!M->hasAttr<OverrideAttr>()) {
- if (M->getLocStart().isFileID()) {
- SourceLocation StartLoc;
- if (M->hasInlineBody()) {
- // Start at the beginning of the body and rewind back to the last
- // non-whitespace character. We will insert the override keyword
- // after that character.
- // FIXME: This transform won't work if there is a comment between
- // the end of the function prototype and the start of the body.
- StartLoc = M->getBody()->getLocStart();
- do {
- StartLoc = StartLoc.getLocWithOffset(-1);
- } while (isWhitespace(*FullSourceLoc(StartLoc, SM).getCharacterData()));
- StartLoc = StartLoc.getLocWithOffset(1);
- } else {
- StartLoc = SM.getSpellingLoc(M->getLocEnd());
- StartLoc = Lexer::getLocForEndOfToken(StartLoc, 0, SM, LangOptions());
- }
- Replace.insert(tooling::Replacement(SM, StartLoc, 0, " override"));
- ++AcceptedChanges;
- }
+ if (M->hasAttr<OverrideAttr>())
+ return;
+
+ // FIXME: Pure methods are not supported yet as it is difficult to track down
+ // the location of '= 0'.
+ if (M->isPure())
+ return;
+
+ if (const FunctionDecl *TemplateMethod = M->getTemplateInstantiationPattern())
+ M = cast<CXXMethodDecl>(TemplateMethod);
+
+ if (M->getParent()->hasAnyDependentBases())
+ return;
+
+ SourceLocation StartLoc;
+ if (M->hasInlineBody()) {
+ // Start at the beginning of the body and rewind back to the last
+ // non-whitespace character. We will insert the override keyword
+ // after that character.
+ // FIXME: This transform won't work if there is a comment between
+ // the end of the function prototype and the start of the body.
+ StartLoc = M->getBody()->getLocStart();
+ do {
+ StartLoc = StartLoc.getLocWithOffset(-1);
+ } while (isWhitespace(*FullSourceLoc(StartLoc, SM).getCharacterData()));
+ StartLoc = StartLoc.getLocWithOffset(1);
+ } else {
+ StartLoc = SM.getSpellingLoc(M->getLocEnd());
+ StartLoc = Lexer::getLocForEndOfToken(StartLoc, 0, SM, LangOptions());
}
+ Replace.insert(tooling::Replacement(SM, StartLoc, 0, " override"));
+ ++AcceptedChanges;
}
-
OpenPOWER on IntegriCloud