mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
C and C++, don't crash during stringification
Specifically when generating display strings for unary expressions and fold expressions. Fixes sphinx-doc/sphinx#7763
This commit is contained in:
parent
e3f9bf43f6
commit
e37d080729
3
CHANGES
3
CHANGES
@ -16,6 +16,9 @@ Features added
|
||||
Bugs fixed
|
||||
----------
|
||||
|
||||
- #7763: C and C++, don't crash during display stringification of unary
|
||||
expressions and fold expressions.
|
||||
|
||||
Testing
|
||||
--------
|
||||
|
||||
|
@ -424,9 +424,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:
|
||||
|
@ -906,12 +906,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(')')
|
||||
@ -1178,9 +1178,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)
|
||||
|
@ -96,6 +96,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*')
|
||||
|
@ -125,6 +125,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')
|
||||
|
Loading…
Reference in New Issue
Block a user