summaryrefslogtreecommitdiff
path: root/src/qdoc/clangcodeparser.cpp
diff options
context:
space:
mode:
authorTopi Reinio <topi.reinio@qt.io>2020-09-29 18:25:18 +0200
committerTopi Reinio <topi.reinio@qt.io>2020-10-08 12:14:29 +0200
commit05ffeba75e90e226cd6ddf7d72cb9b9d0ad5f172 (patch)
tree0530a002323f5112343ba5fee171b799c8fafc85 /src/qdoc/clangcodeparser.cpp
parentc3b26e9a55ae39f2c88a343990bd691351e9efd4 (diff)
downloadqttools-05ffeba75e90e226cd6ddf7d72cb9b9d0ad5f172.tar.gz
qdoc: Document friend functions as related non-members
When parsing a friend declaration in a class, QDoc associated the subsequent function declarations to the namespace scope. This was conceptually correct as friend functions are not class members, but made it impossible to match documentation to these functions using the \fn command; the functions are still found under the class scope in Clang AST, and this has to align with QDoc's node tree for the documentation to be matched correctly. Fix this by letting friend functions remain in the class, keeping track of the friend declarations, and marking friend functions automatically as related non-members. Fixes: QTBUG-86987 Change-Id: I0ad26eed1c72af9302c9e420f5db0ec98c40d86a Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Diffstat (limited to 'src/qdoc/clangcodeparser.cpp')
-rw-r--r--src/qdoc/clangcodeparser.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/qdoc/clangcodeparser.cpp b/src/qdoc/clangcodeparser.cpp
index 8a590f66b..3296e993f 100644
--- a/src/qdoc/clangcodeparser.cpp
+++ b/src/qdoc/clangcodeparser.cpp
@@ -461,6 +461,7 @@ private:
QDocDatabase *qdb_;
Aggregate *parent_;
+ bool m_friendDecl { false }; // true if currently visiting a friend declaration
const QHash<QString, QString> allHeaders_;
QHash<CXFile, bool> isInterestingCache_; // doing a canonicalFilePath is slow, so keep a cache.
@@ -781,15 +782,14 @@ CXChildVisitResult ClangVisitor::visitHeader(CXCursor cursor, CXSourceLocation l
parameters.append(QStringLiteral("..."));
readParameterNamesAndAttributes(fn, cursor);
fn->setTemplateDecl(templateString);
+ // Friend functions are not members
+ if (m_friendDecl)
+ fn->setRelatedNonmember(true);
return CXChildVisit_Continue;
}
#if CINDEX_VERSION >= 36
case CXCursor_FriendDecl: {
- // Friend functions are declared in the enclosing namespace
- Aggregate *ns = parent_;
- while (ns && ns->isClassNode())
- ns = ns->parent();
- QScopedValueRollback<Aggregate *> setParent(parent_, ns);
+ QScopedValueRollback<bool> setFriend(m_friendDecl, true);
// Visit the friend functions
return visitChildren(cursor);
}