summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTopi Reinio <topi.reinio@qt.io>2021-02-19 16:43:51 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-02-22 16:10:43 +0000
commitc3510a4292b7f0ca95f414bf58688c6675bf317b (patch)
tree9d364546f9c0482f6bfa65c0ffb9fdea66674b71
parent90f0d0981d1cb27ca4036b58c394b1a496002c4a (diff)
qdoc: Fix regression in handling of global functions
Commit 550c3031 improved the handling of \relates command, but introduced a regression; When relating a primary function (a first in the linked list of overloads) to another aggregate, the primary's nextOverload pointer was cleared. Subsequent \fn commands trying to document other overloads then failed. The correct way is to move the head of the linked list forward. However, if there are no overloads, we do not want to delete the list entirely, as the function (typically, a global one) must be searchable from the original (global) scope. Fixes: QTBUG-91244 Change-Id: If80fa93ac5231d0676c0809f1acfa97733f9f9e8 Reviewed-by: Topi Reiniƶ <topi.reinio@qt.io> (cherry picked from commit 026edd4bcefd6f0cffa72c2385407c28042b4b36) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/qdoc/aggregate.cpp18
-rw-r--r--tests/auto/qdoc/generatedoutput/expected_output/globals.html48
-rw-r--r--tests/auto/qdoc/generatedoutput/testdata/configs/testglobals.qdocconf6
-rw-r--r--tests/auto/qdoc/generatedoutput/testdata/globalfunc/TestGlobals1
-rw-r--r--tests/auto/qdoc/generatedoutput/testdata/globalfunc/global.h31
-rw-r--r--tests/auto/qdoc/generatedoutput/testdata/globalfunc/global.qdoc48
-rw-r--r--tests/auto/qdoc/generatedoutput/tst_generatedoutput.cpp6
7 files changed, 154 insertions, 4 deletions
diff --git a/src/qdoc/aggregate.cpp b/src/qdoc/aggregate.cpp
index 16b6d5031..7ce1e0310 100644
--- a/src/qdoc/aggregate.cpp
+++ b/src/qdoc/aggregate.cpp
@@ -463,16 +463,26 @@ void Aggregate::addFunction(FunctionNode *fn)
Aggregate's function map.
The function is also removed from the overload list
- that's relative to the the original parent \a firstParent,
- unless it's a primary function.
+ that's relative to the the original parent \a firstParent.
\note This is a private function.
*/
void Aggregate::adoptFunction(FunctionNode *fn, Aggregate *firstParent)
{
auto *primary = firstParent->m_functionMap.value(fn->name());
- if (primary && primary != fn)
- primary->removeOverload(fn);
+ if (primary) {
+ if (primary != fn)
+ primary->removeOverload(fn);
+ else if (primary->nextOverload())
+ firstParent->m_functionMap.insert(primary->name(),
+ primary->nextOverload());
+ /* else...technically we should call
+ firstParent->m_functionMap.remove(primary->name());
+ but we want to be able to still find global functions
+ from the global namespace, even after adopting them
+ elsewhere.
+ */
+ }
fn->setNextOverload(nullptr);
addFunction(fn);
}
diff --git a/tests/auto/qdoc/generatedoutput/expected_output/globals.html b/tests/auto/qdoc/generatedoutput/expected_output/globals.html
new file mode 100644
index 000000000..90f927232
--- /dev/null
+++ b/tests/auto/qdoc/generatedoutput/expected_output/globals.html
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+<!-- global.qdoc -->
+ <title>Globals Class | TestGlobals</title>
+</head>
+<body>
+<li>Globals</li>
+<div class="sidebar">
+<div class="toc">
+<h3><a name="toc">Contents</a></h3>
+<ul>
+<li class="level1"><a href="#related-non-members">Related Non-Members</a></li>
+<li class="level1"><a href="#details">Detailed Description</a></li>
+</ul>
+</div>
+<div class="sidebar-content" id="sidebar-content"></div></div>
+<h1 class="title">Globals Class</h1>
+<div class="table"><table class="alignedsummary">
+<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign"> <span class="preprocessor">#include &lt;Globals&gt;</span>
+</td></tr></table></div><ul>
+</ul>
+<a name="related-non-members"></a>
+<h2 id="related-non-members">Related Non-Members</h2>
+<div class="table"><table class="alignedsummary">
+<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="globals.html#foo">foo</a></b>(int <i>a</i>)</td></tr>
+<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="globals.html#foo-1">foo</a></b>(int <i>a</i>, bool <i>b</i>)</td></tr>
+</table></div>
+<a name="details"></a>
+<!-- $$$Globals-description -->
+<div class="descr">
+<h2 id="details">Detailed Description</h2>
+</div>
+<!-- @@@Globals -->
+<div class="relnonmem">
+<h2>Related Non-Members</h2>
+<!-- $$$foo[overload1]$$$fooint -->
+<h3 class="fn" id="foo"><a name="foo"></a><span class="type">int</span> <span class="name">foo</span>(<span class="type">int</span> <i>a</i>)</h3>
+<p>Params: <i>a</i></p>
+<!-- @@@foo -->
+<!-- $$$foo$$$foointbool -->
+<h3 class="fn" id="foo-1"><a name="foo-1"></a><span class="type">int</span> <span class="name">foo</span>(<span class="type">int</span> <i>a</i>, <span class="type">bool</span> <i>b</i>)</h3>
+<p>Params: <i>b</i>, <i>b</i></p>
+<!-- @@@foo -->
+</div>
+</body>
+</html>
diff --git a/tests/auto/qdoc/generatedoutput/testdata/configs/testglobals.qdocconf b/tests/auto/qdoc/generatedoutput/testdata/configs/testglobals.qdocconf
new file mode 100644
index 000000000..c69ffe239
--- /dev/null
+++ b/tests/auto/qdoc/generatedoutput/testdata/configs/testglobals.qdocconf
@@ -0,0 +1,6 @@
+include(config.qdocconf)
+project = TestGlobals
+includepaths += -I../globalfunc
+
+headers = ../globalfunc/global.h
+sources = ../globalfunc/global.qdoc
diff --git a/tests/auto/qdoc/generatedoutput/testdata/globalfunc/TestGlobals b/tests/auto/qdoc/generatedoutput/testdata/globalfunc/TestGlobals
new file mode 100644
index 000000000..dc4f98a6e
--- /dev/null
+++ b/tests/auto/qdoc/generatedoutput/testdata/globalfunc/TestGlobals
@@ -0,0 +1 @@
+#include "global.h"
diff --git a/tests/auto/qdoc/generatedoutput/testdata/globalfunc/global.h b/tests/auto/qdoc/generatedoutput/testdata/globalfunc/global.h
new file mode 100644
index 000000000..16d3a89cd
--- /dev/null
+++ b/tests/auto/qdoc/generatedoutput/testdata/globalfunc/global.h
@@ -0,0 +1,31 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the tools applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+class Globals {};
+inline int foo(int a) { return a; }
+inline int foo(int a, bool b) { return b ? a : -a; }
diff --git a/tests/auto/qdoc/generatedoutput/testdata/globalfunc/global.qdoc b/tests/auto/qdoc/generatedoutput/testdata/globalfunc/global.qdoc
new file mode 100644
index 000000000..a68a55abd
--- /dev/null
+++ b/tests/auto/qdoc/generatedoutput/testdata/globalfunc/global.qdoc
@@ -0,0 +1,48 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the tools applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/*!
+ \module TestGlobals
+*/
+
+/*!
+ \class Globals
+ \inmodule TestGlobals
+*/
+
+/*!
+ \fn int foo(int a)
+ \relates Globals
+ Params: \a a
+*/
+
+/*!
+ \fn int foo(int a, bool b)
+ \relates Globals
+ Params: \a b, \a b
+*/
diff --git a/tests/auto/qdoc/generatedoutput/tst_generatedoutput.cpp b/tests/auto/qdoc/generatedoutput/tst_generatedoutput.cpp
index 05bfeaa3a..515b816d4 100644
--- a/tests/auto/qdoc/generatedoutput/tst_generatedoutput.cpp
+++ b/tests/auto/qdoc/generatedoutput/tst_generatedoutput.cpp
@@ -78,6 +78,7 @@ private slots:
void usingDirective();
void properties();
void testTagFile();
+ void testGlobalFunctions();
private:
QScopedPointer<QTemporaryDir> m_outputDir;
@@ -512,6 +513,11 @@ void tst_generatedOutput::testTagFile()
testAndCompare("testdata/configs/tagfiles.qdocconf", "testtagfile.tags");
}
+void tst_generatedOutput::testGlobalFunctions()
+{
+ testAndCompare("testdata/configs/testglobals.qdocconf", "globals.html");
+}
+
int main(int argc, char *argv[])
{
tst_generatedOutput tc;