summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Lykke Andersen <Jakob@caput.dk>2020-10-03 16:00:28 +0200
committerJakob Lykke Andersen <Jakob@caput.dk>2020-10-03 16:00:28 +0200
commit777bcb43fa26aeaf34329c56cb1e316da0a1d9e6 (patch)
tree37a1361fdc25b5a0b5ffc67c1fb95a5548605732
parent6f5d45ffff68c2c1892f1a29af0ea1bd5e4e4796 (diff)
downloadsphinx-git-777bcb43fa26aeaf34329c56cb1e316da0a1d9e6.tar.gz
C++, properly reject functions as duplicates
Fixes sphinx-doc/sphinx#8270
-rw-r--r--CHANGES2
-rw-r--r--sphinx/domains/cpp.py5
-rw-r--r--tests/test_domain_cpp.py15
3 files changed, 22 insertions, 0 deletions
diff --git a/CHANGES b/CHANGES
index 564eb799a..93cc5fb8c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -19,6 +19,8 @@ Bugs fixed
* #8188: C, add missing items to internal object types dictionary,
e.g., preventing intersphinx from resolving them.
* C, fix anon objects in intersphinx.
+* #8270, C++, properly reject functions as duplicate declarations if a
+ non-function declaration of the same name already exists.
Testing
diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py
index e5a6201e5..c43c55d5b 100644
--- a/sphinx/domains/cpp.py
+++ b/sphinx/domains/cpp.py
@@ -4360,6 +4360,11 @@ class Symbol:
if Symbol.debug_lookup:
Symbol.debug_print("candId:", candId)
for symbol in withDecl:
+ # but all existing must be functions as well,
+ # otherwise we declare it to be a duplicate
+ if symbol.declaration.objectType != 'function':
+ handleDuplicateDeclaration(symbol, candSymbol)
+ # (not reachable)
oldId = symbol.declaration.get_newest_id()
if Symbol.debug_lookup:
Symbol.debug_print("oldId: ", oldId)
diff --git a/tests/test_domain_cpp.py b/tests/test_domain_cpp.py
index 558d69911..ec7a2b262 100644
--- a/tests/test_domain_cpp.py
+++ b/tests/test_domain_cpp.py
@@ -1236,3 +1236,18 @@ def test_noindexentry(app):
assert_node(doctree, (addnodes.index, desc, addnodes.index, desc))
assert_node(doctree[0], addnodes.index, entries=[('single', 'f (C++ function)', '_CPPv41fv', '', None)])
assert_node(doctree[2], addnodes.index, entries=[])
+
+
+def test_mix_decl_duplicate(app, warning):
+ # Issue 8270
+ text = (".. cpp:struct:: A\n"
+ ".. cpp:function:: void A()\n"
+ ".. cpp:struct:: A\n")
+ restructuredtext.parse(app, text)
+ ws = warning.getvalue().split("\n")
+ assert len(ws) == 5
+ assert "index.rst:2: WARNING: Duplicate C++ declaration, also defined in 'index'." in ws[0]
+ assert "Declaration is 'void A()'." in ws[1]
+ assert "index.rst:3: WARNING: Duplicate C++ declaration, also defined in 'index'." in ws[2]
+ assert "Declaration is 'A'." in ws[3]
+ assert ws[4] == "" \ No newline at end of file