From 76ae5780c4ada9a44e35103fcc1247ff2b7fc53d Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 28 Oct 2020 11:10:34 +0100 Subject: [PATCH] CppTools: Fix function decl/def look-up ... in the presence of macros. For instance, renaming a parameter of a function preceded by some sort of DLL_EXPORT macro would not offer to apply the change to the definition, because the macro gets expanded and the respective tokens have bogus offsets derived from the place where the macro is defined. Luckily, such tokens are marked as "generated" and we can skip them for the purposes of retrieving the actual location of the function. Fixes: QTCREATORBUG-24739 Change-Id: If5db355b1c301060a17a687c2b5582fa1ef17d3f Reviewed-by: Christian Stenger --- src/plugins/cpptools/cpprefactoringchanges.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/plugins/cpptools/cpprefactoringchanges.cpp b/src/plugins/cpptools/cpprefactoringchanges.cpp index a86dd6451b2..e0ca3111b95 100644 --- a/src/plugins/cpptools/cpprefactoringchanges.cpp +++ b/src/plugins/cpptools/cpprefactoringchanges.cpp @@ -227,7 +227,11 @@ int CppRefactoringFile::startOf(unsigned index) const int CppRefactoringFile::startOf(const AST *ast) const { - return startOf(ast->firstToken()); + int firstToken = ast->firstToken(); + const int lastToken = ast->lastToken(); + while (tokenAt(firstToken).generated() && firstToken < lastToken) + ++firstToken; + return startOf(firstToken); } int CppRefactoringFile::endOf(unsigned index) const @@ -239,9 +243,12 @@ int CppRefactoringFile::endOf(unsigned index) const int CppRefactoringFile::endOf(const AST *ast) const { - int end = ast->lastToken(); - QTC_ASSERT(end > 0, return -1); - return endOf(end - 1); + int lastToken = ast->lastToken() - 1; + QTC_ASSERT(lastToken >= 0, return -1); + const int firstToken = ast->firstToken(); + while (tokenAt(lastToken).generated() && lastToken > firstToken) + --lastToken; + return endOf(lastToken); } void CppRefactoringFile::startAndEndOf(unsigned index, int *start, int *end) const