diff --git a/kdevplatform/language/duchain/functiondefinition.cpp b/kdevplatform/language/duchain/functiondefinition.cpp --- a/kdevplatform/language/duchain/functiondefinition.cpp +++ b/kdevplatform/language/duchain/functiondefinition.cpp @@ -85,6 +85,10 @@ return nullptr; } + if (decl->isFunctionDeclaration() && decl->isDefinition()) { + return const_cast(static_cast (decl)); + } + const KDevVarLengthArray allDefinitions = DUChain::definitions()->definitions(decl->id()); for (const IndexedDeclaration decl : allDefinitions) { if(decl.data()) ///@todo Find better ways of deciding which definition to use diff --git a/plugins/clang/tests/test_duchain.h b/plugins/clang/tests/test_duchain.h --- a/plugins/clang/tests/test_duchain.h +++ b/plugins/clang/tests/test_duchain.h @@ -102,6 +102,8 @@ void testQtIntegration(); void testHasInclude(); + void testSameFunctionDefinition(); + private: QScopedPointer m_provider; KDevelop::TestProjectController* m_projectController; diff --git a/plugins/clang/tests/test_duchain.cpp b/plugins/clang/tests/test_duchain.cpp --- a/plugins/clang/tests/test_duchain.cpp +++ b/plugins/clang/tests/test_duchain.cpp @@ -2086,3 +2086,45 @@ } } } + +void TestDUChain::testSameFunctionDefinition() +{ + QString source(QStringLiteral(R"( + #include + #include + + void configure() + { + printf("do stuff\n"); + } + )")); + + QTemporaryDir dir; + auto project = new TestProject(Path(dir.path()), this); + m_projectController->addProject(project); + + TestFile file1(source, QStringLiteral("c"), project); + TestFile file2(source, QStringLiteral("c"), project); + TestFile file3(source, QStringLiteral("c"), project); + + file1.parse(TopDUContext::AllDeclarationsContextsAndUses); + file2.parse(TopDUContext::AllDeclarationsContextsAndUses); + file3.parse(TopDUContext::AllDeclarationsContextsAndUses); + + QVERIFY(file1.waitForParsed(1000)); + QVERIFY(file2.waitForParsed(1000)); + QVERIFY(file3.waitForParsed(1000)); + + auto checkFunctionDefinition = [] (TestFile & file) { + DUChainReadLocker lock; + QCOMPARE(file.topContext()->localDeclarations().count(), 1); + auto configureFunc = file.topContext()->localDeclarations().first(); + QCOMPARE(FunctionDefinition::definition(configureFunc), configureFunc); + }; + + checkFunctionDefinition(file1); + checkFunctionDefinition(file2); + checkFunctionDefinition(file3); + + m_projectController->closeAllProjects(); +}