Emit preprocessor expr error for unary + on string

Previously other unary operators on a string all gave an error, but
unary + was handled as a no-op and so didn't.
This commit is contained in:
Olly Betts 2022-02-24 09:50:22 +13:00
commit 4986b8793d
3 changed files with 38 additions and 5 deletions

View file

@ -51,3 +51,18 @@
/* This didn't fail prior with SWIG < 4.1. Github #1384. */
#if 1 == ("TWO")
#endif
/* These should all give errors. */
#if "1"
#endif
#if -"1"
#endif
#if "1" == -"-1"
#endif
#if "1" == !"-1"
#endif
#if "1" == ~"1"
#endif
/* Unary + was a no-op and so this didn't give an error in SWIG < 4.1.0. */
#if "1" == +"1"
#endif

View file

@ -21,3 +21,13 @@ pp_expressions_bad.i:48: Warning 202: Could not evaluate expression '"TWO" == 1'
pp_expressions_bad.i:48: Warning 202: Can't mix strings and integers in expression
pp_expressions_bad.i:52: Warning 202: Could not evaluate expression '1 == ("TWO")'
pp_expressions_bad.i:52: Warning 202: Can't mix strings and integers in expression
pp_expressions_bad.i:58: Warning 202: Could not evaluate expression '-"1"'
pp_expressions_bad.i:58: Warning 202: Syntax error: attempt to apply unary operator to string
pp_expressions_bad.i:60: Warning 202: Could not evaluate expression '"1" == -"-1"'
pp_expressions_bad.i:60: Warning 202: Syntax error: attempt to apply unary operator to string
pp_expressions_bad.i:62: Warning 202: Could not evaluate expression '"1" == !"-1"'
pp_expressions_bad.i:62: Warning 202: Syntax error: attempt to apply unary operator to string
pp_expressions_bad.i:64: Warning 202: Could not evaluate expression '"1" == ~"1"'
pp_expressions_bad.i:64: Warning 202: Syntax error: attempt to apply unary operator to string
pp_expressions_bad.i:67: Warning 202: Could not evaluate expression '"1" == +"1"'
pp_expressions_bad.i:67: Warning 202: Syntax error: attempt to apply unary operator to string