From 66f98957b1ff8636d47a2f1e4cfaff4432618cfe Mon Sep 17 00:00:00 2001 From: Jakob Lykke Andersen Date: Fri, 29 Jul 2022 17:22:14 +0200 Subject: [PATCH] C++, ensure merging case is as assumed --- sphinx/domains/cpp.py | 11 ++++++----- tests/test_domain_cpp.py | 16 ++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index e9f6264fdb..3b11f15e94 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -4850,7 +4850,7 @@ class Symbol: if symbol.declaration is None: if Symbol.debug_lookup: Symbol.debug_print("empty candidate") - # if in the end we have non matching, but have an empty one, + # if in the end we have non-matching, but have an empty one, # then just continue with that ourChild = symbol continue @@ -4880,10 +4880,10 @@ class Symbol: if (otherChild.declaration.objectType == ourChild.declaration.objectType and otherChild.declaration.objectType in - ('templateParam', 'functionParam')): - # `ourChild` was presumably just created during mergging - # by the call to `_fill_empty` on the parent and can be - # ignored. + ('templateParam', 'functionParam') and + ourChild.parent.declaration == otherChild.parent.declaration): + # `ourChild` was just created during merging by the call + # to `_fill_empty` on the parent and can be ignored. pass else: # Both have declarations, and in the same docname. @@ -5153,6 +5153,7 @@ class Symbol: res.append(": ") if self.isRedeclaration: res.append('!!duplicate!! ') + res.append("{" + self.declaration.objectType + "} ") res.append(str(self.declaration)) if self.docname: res.append('\t(') diff --git a/tests/test_domain_cpp.py b/tests/test_domain_cpp.py index 23c496b458..41ea21e3d7 100644 --- a/tests/test_domain_cpp.py +++ b/tests/test_domain_cpp.py @@ -1414,8 +1414,8 @@ def test_domain_cpp_normalize_unspecialized_template_args(make_app, app_params): assert root1.dump(1) == ( ' ::\n' ' template \n' - ' A: template A\t(text1)\n' - ' T: typename T\t(text1)\n' + ' A: {class} template A\t(text1)\n' + ' T: {templateParam} typename T\t(text1)\n' ) app2 = make_app(*args, **kwargs) @@ -1428,8 +1428,8 @@ def test_domain_cpp_normalize_unspecialized_template_args(make_app, app_params): ' A\n' ' T\n' ' template \n' - ' B: template template A::B\t(text2)\n' - ' U: typename U\t(text2)\n' + ' B: {class} template template A::B\t(text2)\n' + ' U: {templateParam} typename U\t(text2)\n' ) root2.merge_with(root1, ['text1'], app2.env) @@ -1437,11 +1437,11 @@ def test_domain_cpp_normalize_unspecialized_template_args(make_app, app_params): assert root2.dump(1) == ( ' ::\n' ' template \n' - ' A: template A\t(text1)\n' - ' T: typename T\t(text1)\n' + ' A: {class} template A\t(text1)\n' + ' T: {templateParam} typename T\t(text1)\n' ' template \n' - ' B: template template A::B\t(text2)\n' - ' U: typename U\t(text2)\n' + ' B: {class} template template A::B\t(text2)\n' + ' U: {templateParam} typename U\t(text2)\n' ) warning = app2._warning.getvalue() assert 'Internal C++ domain error during symbol merging' not in warning