diff options
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | sphinx/domains/c.py | 4 | ||||
-rw-r--r-- | sphinx/domains/cpp.py | 8 | ||||
-rw-r--r-- | tests/test_domain_c.py | 9 | ||||
-rw-r--r-- | tests/test_domain_cpp.py | 9 |
5 files changed, 27 insertions, 6 deletions
@@ -156,6 +156,9 @@ Features added Bugs fixed ---------- +- #7763: C and C++, don't crash during display stringification of unary + expressions and fold expressions. + Testing -------- diff --git a/sphinx/domains/c.py b/sphinx/domains/c.py index 164a87254..36a8f1f65 100644 --- a/sphinx/domains/c.py +++ b/sphinx/domains/c.py @@ -432,9 +432,9 @@ class ASTUnaryOpExpr(ASTExpression): def _stringify(self, transform: StringifyTransform) -> str: if self.op[0] in 'cn': - return transform(self.op) + " " + transform(self.expr) + return self.op + " " + transform(self.expr) else: - return transform(self.op) + transform(self.expr) + return self.op + transform(self.expr) def describe_signature(self, signode: TextElement, mode: str, env: "BuildEnvironment", symbol: "Symbol") -> None: diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index b801f4030..dca69bace 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -951,12 +951,12 @@ class ASTFoldExpr(ASTExpression): if self.leftExpr: res.append(transform(self.leftExpr)) res.append(' ') - res.append(transform(self.op)) + res.append(self.op) res.append(' ') res.append('...') if self.rightExpr: res.append(' ') - res.append(transform(self.op)) + res.append(self.op) res.append(' ') res.append(transform(self.rightExpr)) res.append(')') @@ -1223,9 +1223,9 @@ class ASTUnaryOpExpr(ASTExpression): def _stringify(self, transform: StringifyTransform) -> str: if self.op[0] in 'cn': - return transform(self.op) + " " + transform(self.expr) + return self.op + " " + transform(self.expr) else: - return transform(self.op) + transform(self.expr) + return self.op + transform(self.expr) def get_id(self, version: int) -> str: return _id_operator_unary_v2[self.op] + self.expr.get_id(version) diff --git a/tests/test_domain_c.py b/tests/test_domain_c.py index 2a5663323..10a20b9d1 100644 --- a/tests/test_domain_c.py +++ b/tests/test_domain_c.py @@ -126,6 +126,15 @@ def test_expressions(): print("Result: ", res) print("Expected: ", output) raise DefinitionError("") + displayString = ast.get_display_string() + if res != displayString: + # note: if the expression contains an anon name then this will trigger a falsely + print("") + print("Input: ", expr) + print("Result: ", res) + print("Display: ", displayString) + raise DefinitionError("") + # type expressions exprCheck('int*') exprCheck('int *const*') diff --git a/tests/test_domain_cpp.py b/tests/test_domain_cpp.py index ca70c4fd8..116acecfb 100644 --- a/tests/test_domain_cpp.py +++ b/tests/test_domain_cpp.py @@ -155,6 +155,15 @@ def test_expressions(): print("Input: ", expr) print("Result: ", res) raise DefinitionError("") + displayString = ast.get_display_string() + if res != displayString: + # note: if the expression contains an anon name then this will trigger a falsely + print("") + print("Input: ", expr) + print("Result: ", res) + print("Display: ", displayString) + raise DefinitionError("") + # primary exprCheck('nullptr', 'LDnE') exprCheck('true', 'L1E') |