diff --git a/CHANGES b/CHANGES index 5851b4622e..dc55e910b8 100644 --- a/CHANGES +++ b/CHANGES @@ -61,6 +61,7 @@ Bugs fixed * #7461: py domain: fails with IndexError for empty tuple in type annotation * #7461: autodoc: empty tuple in type annotation is not shown correctly +* C++, fix spacing issue in east-const declarations. Testing -------- diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index e09a56b06f..7915f41283 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -2062,12 +2062,15 @@ class ASTDeclSpecs(ASTBase): if self.trailingTypeSpec: if addSpace: signode += nodes.Text(' ') + numChildren = len(signode) self.trailingTypeSpec.describe_signature(signode, mode, env, symbol=symbol) - numChildren = len(signode) - self.rightSpecs.describe_signature(signode) - if len(signode) != numChildren: - signode += nodes.Text(' ') + addSpace = len(signode) != numChildren + + if len(str(self.rightSpecs)) > 0: + if addSpace: + signode += nodes.Text(' ') + self.rightSpecs.describe_signature(signode) # Declarator diff --git a/tests/roots/test-ext-autodoc/target/__init__.py b/tests/roots/test-ext-autodoc/target/__init__.py index e28eeef8a6..b6684ee85b 100644 --- a/tests/roots/test-ext-autodoc/target/__init__.py +++ b/tests/roots/test-ext-autodoc/target/__init__.py @@ -145,6 +145,8 @@ First line of docstring class StrRepr(str): + """docstring""" + def __repr__(self): return self