diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2017-09-17 19:02:55 +0100 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2017-09-17 19:02:55 +0100 |
commit | 90ba174fcea1618af57aa594199541d47a89b7f6 (patch) | |
tree | 72364cb20f5aefcd2c2decb90d351149f204a5c1 | |
parent | 323d606d3cf4e0479608a75e187ad059f31c9f0d (diff) | |
download | swig-90ba174fcea1618af57aa594199541d47a89b7f6.tar.gz |
Fix generated code for constant expressions containing wchar_t L literals.
Such as:
# define __WCHAR_MAX (0x7fffffff + L'\0')
Reported on swig-user mailing list.
-rw-r--r-- | CHANGES.current | 5 | ||||
-rw-r--r-- | Examples/test-suite/csharp/preproc_constants_c_runme.cs | 3 | ||||
-rw-r--r-- | Examples/test-suite/csharp/preproc_constants_runme.cs | 2 | ||||
-rw-r--r-- | Examples/test-suite/d/preproc_constants_c_runme.1.d | 2 | ||||
-rw-r--r-- | Examples/test-suite/d/preproc_constants_c_runme.2.d | 2 | ||||
-rw-r--r-- | Examples/test-suite/d/preproc_constants_runme.1.d | 2 | ||||
-rw-r--r-- | Examples/test-suite/d/preproc_constants_runme.2.d | 2 | ||||
-rw-r--r-- | Examples/test-suite/php/preproc_constants_c_runme.php | 2 | ||||
-rw-r--r-- | Examples/test-suite/php/preproc_constants_runme.php | 2 | ||||
-rw-r--r-- | Examples/test-suite/php5/preproc_constants_c_runme.php | 2 | ||||
-rw-r--r-- | Examples/test-suite/php5/preproc_constants_runme.php | 2 | ||||
-rw-r--r-- | Examples/test-suite/preproc_constants.i | 3 | ||||
-rw-r--r-- | Source/CParse/parser.y | 2 |
13 files changed, 29 insertions, 2 deletions
diff --git a/CHANGES.current b/CHANGES.current index 1e4a24488..b455a9f6e 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,11 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.0.0 (in progress) =========================== +2017-09-17: wsfulton + Fix generated code for constant expressions containing wchar_t L literals such as: + # define __WCHAR_MAX (0x7fffffff + L'\0') + # define __WCHAR_MIN (-__WCHAR_MAX - 1) + 2017-09-10: mlamarre [Python] Patch #1083. Define_DEBUG to 1 to do exactly like Visual Studio /LDd, /MDd or /MTd compiler options. diff --git a/Examples/test-suite/csharp/preproc_constants_c_runme.cs b/Examples/test-suite/csharp/preproc_constants_c_runme.cs index 76c684d85..1c28e49d9 100644 --- a/Examples/test-suite/csharp/preproc_constants_c_runme.cs +++ b/Examples/test-suite/csharp/preproc_constants_c_runme.cs @@ -61,7 +61,8 @@ public class runme { assert( typeof(int) == preproc_constants_c.EXPR_LAND.GetType() ); assert( typeof(int) == preproc_constants_c.EXPR_LOR.GetType() ); assert( typeof(double) == preproc_constants_c.EXPR_CONDITIONAL.GetType() ); - + assert( typeof(int) == preproc_constants_c.EXPR_WCHAR_MAX.GetType() ); + assert( typeof(int) == preproc_constants_c.EXPR_WCHAR_MIN.GetType() ); } static void assert(bool assertion) { if (!assertion) diff --git a/Examples/test-suite/csharp/preproc_constants_runme.cs b/Examples/test-suite/csharp/preproc_constants_runme.cs index 9fae5914a..6b02e3057 100644 --- a/Examples/test-suite/csharp/preproc_constants_runme.cs +++ b/Examples/test-suite/csharp/preproc_constants_runme.cs @@ -60,6 +60,8 @@ public class runme { assert( typeof(bool) == preproc_constants.EXPR_LAND.GetType() ); assert( typeof(bool) == preproc_constants.EXPR_LOR.GetType() ); assert( typeof(double) == preproc_constants.EXPR_CONDITIONAL.GetType() ); + assert( typeof(int) == preproc_constants.EXPR_WCHAR_MAX.GetType() ); + assert( typeof(int) == preproc_constants.EXPR_WCHAR_MIN.GetType() ); } static void assert(bool assertion) { diff --git a/Examples/test-suite/d/preproc_constants_c_runme.1.d b/Examples/test-suite/d/preproc_constants_c_runme.1.d index d846c71ac..2b349afd5 100644 --- a/Examples/test-suite/d/preproc_constants_c_runme.1.d +++ b/Examples/test-suite/d/preproc_constants_c_runme.1.d @@ -61,4 +61,6 @@ void main() { static assert(is(int == typeof(EXPR_LAND()))); static assert(is(int == typeof(EXPR_LOR()))); static assert(is(double == typeof(EXPR_CONDITIONAL()))); + static assert(is(int == typeof(EXPR_WCHAR_MAX()))); + static assert(is(int == typeof(EXPR_WCHAR_MIN()))); } diff --git a/Examples/test-suite/d/preproc_constants_c_runme.2.d b/Examples/test-suite/d/preproc_constants_c_runme.2.d index 9bdbb9372..1bac52578 100644 --- a/Examples/test-suite/d/preproc_constants_c_runme.2.d +++ b/Examples/test-suite/d/preproc_constants_c_runme.2.d @@ -61,4 +61,6 @@ void main() { static assert(is(int == typeof(EXPR_LAND()))); static assert(is(int == typeof(EXPR_LOR()))); static assert(is(double == typeof(EXPR_CONDITIONAL()))); + static assert(is(int == typeof(EXPR_WCHAR_MAX()))); + static assert(is(int == typeof(EXPR_WCHAR_MIN()))); } diff --git a/Examples/test-suite/d/preproc_constants_runme.1.d b/Examples/test-suite/d/preproc_constants_runme.1.d index 009405fc7..f743f4850 100644 --- a/Examples/test-suite/d/preproc_constants_runme.1.d +++ b/Examples/test-suite/d/preproc_constants_runme.1.d @@ -60,4 +60,6 @@ void main() { static assert(is(bool == typeof(EXPR_LAND()))); static assert(is(bool == typeof(EXPR_LOR()))); static assert(is(double == typeof(EXPR_CONDITIONAL()))); + static assert(is(int == typeof(EXPR_WCHAR_MAX()))); + static assert(is(int == typeof(EXPR_WCHAR_MIN()))); } diff --git a/Examples/test-suite/d/preproc_constants_runme.2.d b/Examples/test-suite/d/preproc_constants_runme.2.d index 2d92ef052..0d96c3733 100644 --- a/Examples/test-suite/d/preproc_constants_runme.2.d +++ b/Examples/test-suite/d/preproc_constants_runme.2.d @@ -60,4 +60,6 @@ void main() { static assert(is(bool == typeof(EXPR_LAND()))); static assert(is(bool == typeof(EXPR_LOR()))); static assert(is(double == typeof(EXPR_CONDITIONAL()))); + static assert(is(int == typeof(EXPR_WCHAR_MAX()))); + static assert(is(int == typeof(EXPR_WCHAR_MIN()))); } diff --git a/Examples/test-suite/php/preproc_constants_c_runme.php b/Examples/test-suite/php/preproc_constants_c_runme.php index af9b76e1c..e59fe18ee 100644 --- a/Examples/test-suite/php/preproc_constants_c_runme.php +++ b/Examples/test-suite/php/preproc_constants_c_runme.php @@ -62,5 +62,7 @@ check::equal(gettype(preproc_constants_c::EXPR_OR), "integer", "preproc_constant check::equal(gettype(preproc_constants_c::EXPR_LAND), "integer", "preproc_constants.EXPR_LAND has unexpected type"); check::equal(gettype(preproc_constants_c::EXPR_LOR), "integer", "preproc_constants.EXPR_LOR has unexpected type"); check::equal(gettype(preproc_constants_c::EXPR_CONDITIONAL), "double", "preproc_constants.EXPR_CONDITIONAL has unexpected type"); +check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type"); +check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type"); ?> diff --git a/Examples/test-suite/php/preproc_constants_runme.php b/Examples/test-suite/php/preproc_constants_runme.php index 5c9119b3e..8e117ea16 100644 --- a/Examples/test-suite/php/preproc_constants_runme.php +++ b/Examples/test-suite/php/preproc_constants_runme.php @@ -61,5 +61,7 @@ check::equal(gettype(preproc_constants::EXPR_OR), "integer", "preproc_constants. check::equal(gettype(preproc_constants::EXPR_LAND), "boolean", "preproc_constants.EXPR_LAND has unexpected type"); check::equal(gettype(preproc_constants::EXPR_LOR), "boolean", "preproc_constants.EXPR_LOR has unexpected type"); check::equal(gettype(preproc_constants::EXPR_CONDITIONAL), "double", "preproc_constants.EXPR_CONDITIONAL has unexpected type"); +check::equal(gettype(preproc_constants::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type"); +check::equal(gettype(preproc_constants::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type"); ?> diff --git a/Examples/test-suite/php5/preproc_constants_c_runme.php b/Examples/test-suite/php5/preproc_constants_c_runme.php index 1ea01950e..d978fabcb 100644 --- a/Examples/test-suite/php5/preproc_constants_c_runme.php +++ b/Examples/test-suite/php5/preproc_constants_c_runme.php @@ -62,5 +62,7 @@ check::equal(gettype(preproc_constants_c::EXPR_OR), "integer", "preproc_constant check::equal(gettype(preproc_constants_c::EXPR_LAND), "integer", "preproc_constants.EXPR_LAND has unexpected type"); check::equal(gettype(preproc_constants_c::EXPR_LOR), "integer", "preproc_constants.EXPR_LOR has unexpected type"); check::equal(gettype(preproc_constants_c::EXPR_CONDITIONAL), "double", "preproc_constants.EXPR_CONDITIONAL has unexpected type"); +check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type"); +check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type"); ?> diff --git a/Examples/test-suite/php5/preproc_constants_runme.php b/Examples/test-suite/php5/preproc_constants_runme.php index fb9ee4fa7..75270269e 100644 --- a/Examples/test-suite/php5/preproc_constants_runme.php +++ b/Examples/test-suite/php5/preproc_constants_runme.php @@ -70,5 +70,7 @@ check::equal(gettype(preproc_constants::EXPR_LAND), "integer", "preproc_constant check::equal(gettype(preproc_constants::EXPR_LOR), "integer", "preproc_constants.EXPR_LOR has unexpected type"); check::equal(gettype(preproc_constants::EXPR_CONDITIONAL), "double", "preproc_constants.EXPR_CONDITIONAL has unexpected type"); +check::equal(gettype(preproc_constants::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type"); +check::equal(gettype(preproc_constants::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type"); ?> diff --git a/Examples/test-suite/preproc_constants.i b/Examples/test-suite/preproc_constants.i index 3a999ada3..16b44c901 100644 --- a/Examples/test-suite/preproc_constants.i +++ b/Examples/test-suite/preproc_constants.i @@ -87,6 +87,9 @@ #define EXPR_LOR 0xFF || 1 #define EXPR_CONDITIONAL true ? 2 : 2.2 +#define EXPR_WCHAR_MAX (0x7fffffff + L'\0') +#define EXPR_WCHAR_MIN (-EXPR_WCHAR_MAX - 1) + #define EXPR_CHAR_COMPOUND_ADD 'A' + 12 #define EXPR_CHAR_COMPOUND_LSHIFT 'B' << 6 #define H_SUPPRESS_SCALING_MAGIC (('s'<<24) | ('u'<<16) | ('p'<<8) | 'p') diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 2e92cd01b..273dadba8 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -194,7 +194,7 @@ int SWIG_cparse_template_reduce(int treduce) { * ----------------------------------------------------------------------------- */ static int promote_type(int t) { - if (t <= T_UCHAR || t == T_CHAR) return T_INT; + if (t <= T_UCHAR || t == T_CHAR || t == T_WCHAR) return T_INT; return t; } |