forked from qt-creator/qt-creator
C++: Fix find usage to see Catch test functions bodies
Catch test functions defined with function-like macros. To speed-up semantic analysis, find usages does not expand function-like macros. Semantic fails with "expected a function declarator" on such functions and skips function body. To avoid that, we create dummy function type specifically for this case Change-Id: Ie2f2464ee57aa4dc86eed07b8b699458f95c0266 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
13
src/libs/3rdparty/cplusplus/Bind.cpp
vendored
13
src/libs/3rdparty/cplusplus/Bind.cpp
vendored
@@ -2252,6 +2252,19 @@ bool Bind::visit(FunctionDefinitionAST *ast)
|
||||
Function *fun = type->asFunctionType();
|
||||
ast->symbol = fun;
|
||||
|
||||
if (!fun && ast->declarator && ast->declarator->initializer)
|
||||
if (ExpressionListParenAST *exprAst = ast->declarator->initializer->asExpressionListParen()) {
|
||||
// this could be non-expanded function like macro, because
|
||||
// for find usages we parse without expanding them
|
||||
// So we create dummy function type here for findUsages to see function body
|
||||
fun = control()->newFunction(0, nullptr);
|
||||
fun->setStartOffset(tokenAt(exprAst->firstToken()).utf16charsBegin());
|
||||
fun->setEndOffset(tokenAt(exprAst->lastToken() - 1).utf16charsEnd());
|
||||
|
||||
type = fun;
|
||||
ast->symbol = fun;
|
||||
}
|
||||
|
||||
if (fun) {
|
||||
setDeclSpecifiers(fun, declSpecifiers);
|
||||
fun->setEndOffset(tokenAt(ast->lastToken() - 1).utf16charsEnd());
|
||||
|
||||
Reference in New Issue
Block a user