Skip to content

Commit 713481f

Browse files
authored
Merge pull request godotengine#1919 from dsnopek/int-min-error
Workaround `unary minus operator applied to unsigned type` error in MSVC with `-2147483648`
2 parents b058594 + 935a616 commit 713481f

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

binding_generator.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,13 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
18311831
for value in class_api["constants"]:
18321832
if "type" not in value:
18331833
value["type"] = "int"
1834-
result.append(f"\tstatic const {value['type']} {value['name']} = {value['value']};")
1834+
const_value = value["value"]
1835+
if value["type"] == "int" and const_value == -2147483648:
1836+
# -2147483648 is a valid value for int, but MSVC doesn't read the whole thing as a literal,
1837+
# instead it sees 2147483648 (which is too big for an an int) and then applies the unary minus.
1838+
# This is a workaround for that.
1839+
const_value = "-2147483647 - 1"
1840+
result.append(f"\tstatic const {value['type']} {value['name']} = {const_value};")
18351841
result.append("")
18361842

18371843
if is_singleton:

0 commit comments

Comments
 (0)