Skip to content

Commit d4c90ab

Browse files
committed
C, duplicate warnings for tagged names
1 parent 6f3426e commit d4c90ab

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

sphinx/domains/c.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ def matches(self, other: "ASTIdentifier") -> bool:
135135
return False
136136
if self.tag is None:
137137
return True
138-
return self.tag == other.tag
138+
assert other.tag is not None
139+
isTag = self.tag == ''
140+
isOtherTag = other.tag == ''
141+
return isTag == isOtherTag
139142

140143
# and this is where we finally make a difference between __str__ and the display string
141144

tests/test_domain_c.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,21 @@ def test_ids_vs_tags2(app, warning):
673673
assert len(ws) == 0
674674

675675

676+
def test_duplicate_tags(app, warning):
677+
text = """
678+
.. c:struct:: A
679+
.. c:union:: A
680+
.. c:enum:: A
681+
"""
682+
restructuredtext.parse(app, text)
683+
ws = split_warnigns(warning)
684+
assert len(ws) == 4
685+
assert "index.rst:3: WARNING: Duplicate C declaration" in ws[0]
686+
assert "Declaration is '.. c:union:: A'." in ws[1]
687+
assert "index.rst:4: WARNING: Duplicate C declaration" in ws[2]
688+
assert "Declaration is '.. c:enum:: A'." in ws[3]
689+
690+
676691
def test_build_domain_c_semicolon(app, warning):
677692
text = """
678693
.. c:member:: int member;

0 commit comments

Comments
 (0)