c531d3
From 9e2a12416cf6ce7b926829aff353fe2d9019f135 Mon Sep 17 00:00:00 2001
c531d3
From: William S Fulton <wsf@fultondesigns.co.uk>
c531d3
Date: Mon, 18 Sep 2017 07:06:27 +0100
c531d3
Subject: [PATCH 2/2] Fix type promotion wrapping some non-trivial constant
c531d3
 expressions
c531d3
c531d3
This was previously an integral type instead of a floating point type:
c531d3
---
c531d3
 CHANGES.current                                         | 5 +++++
c531d3
 Examples/test-suite/csharp/preproc_constants_c_runme.cs | 1 +
c531d3
 Examples/test-suite/csharp/preproc_constants_runme.cs   | 1 +
c531d3
 Examples/test-suite/d/preproc_constants_c_runme.1.d     | 1 +
c531d3
 Examples/test-suite/d/preproc_constants_c_runme.2.d     | 1 +
c531d3
 Examples/test-suite/d/preproc_constants_runme.1.d       | 1 +
c531d3
 Examples/test-suite/d/preproc_constants_runme.2.d       | 1 +
c531d3
 Examples/test-suite/php/preproc_constants_c_runme.php   | 1 +
c531d3
 Examples/test-suite/php/preproc_constants_runme.php     | 1 +
c531d3
 Examples/test-suite/php5/preproc_constants_c_runme.php  | 1 +
c531d3
 Examples/test-suite/php5/preproc_constants_runme.php    | 1 +
c531d3
 Examples/test-suite/preproc_constants.i                 | 1 +
c531d3
 Source/CParse/parser.y                                  | 1 +
c531d3
 13 files changed, 17 insertions(+)
c531d3
c531d3
#diff --git a/CHANGES.current b/CHANGES.current
c531d3
#index b455a9f..f76e5a5 100644
c531d3
#--- a/CHANGES.current
c531d3
#+++ b/CHANGES.current
c531d3
#@@ -7,6 +7,11 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
c531d3
# Version 4.0.0 (in progress)
c531d3
# ===========================
c531d3
# 
c531d3
#+2017-09-18: wsfulton
c531d3
#+            Fix type promotion wrapping constant expressions of the form:
c531d3
#+              # define EXPR_MIXED1    (0x80 + 11.1) - 1
c531d3
#+            This was previously an integral type instead of a floating point type.
c531d3
#+
c531d3
# 2017-09-17: wsfulton
c531d3
#             Fix generated code for constant expressions containing wchar_t L literals such as:
c531d3
#               # define __WCHAR_MAX    (0x7fffffff + L'\0')
c531d3
diff --git a/Examples/test-suite/csharp/preproc_constants_c_runme.cs b/Examples/test-suite/csharp/preproc_constants_c_runme.cs
c531d3
index 1c28e49..7f40ce4 100644
c531d3
--- a/Examples/test-suite/csharp/preproc_constants_c_runme.cs
c531d3
+++ b/Examples/test-suite/csharp/preproc_constants_c_runme.cs
c531d3
@@ -61,6 +61,7 @@ public class runme {
c531d3
     assert( typeof(int) == preproc_constants_c.EXPR_LAND.GetType() );
c531d3
     assert( typeof(int) == preproc_constants_c.EXPR_LOR.GetType() );
c531d3
     assert( typeof(double) == preproc_constants_c.EXPR_CONDITIONAL.GetType() );
c531d3
+    assert( typeof(double) == preproc_constants_c.EXPR_MIXED1.GetType() );
c531d3
     assert( typeof(int) == preproc_constants_c.EXPR_WCHAR_MAX.GetType() );
c531d3
     assert( typeof(int) == preproc_constants_c.EXPR_WCHAR_MIN.GetType() );
c531d3
   }
c531d3
diff --git a/Examples/test-suite/csharp/preproc_constants_runme.cs b/Examples/test-suite/csharp/preproc_constants_runme.cs
c531d3
index 6b02e30..0d8981f 100644
c531d3
--- a/Examples/test-suite/csharp/preproc_constants_runme.cs
c531d3
+++ b/Examples/test-suite/csharp/preproc_constants_runme.cs
c531d3
@@ -60,6 +60,7 @@ public class runme {
c531d3
     assert( typeof(bool) == preproc_constants.EXPR_LAND.GetType() );
c531d3
     assert( typeof(bool) == preproc_constants.EXPR_LOR.GetType() );
c531d3
     assert( typeof(double) == preproc_constants.EXPR_CONDITIONAL.GetType() );
c531d3
+    assert( typeof(double) == preproc_constants.EXPR_MIXED1.GetType() );
c531d3
     assert( typeof(int) == preproc_constants.EXPR_WCHAR_MAX.GetType() );
c531d3
     assert( typeof(int) == preproc_constants.EXPR_WCHAR_MIN.GetType() );
c531d3
 
c531d3
diff --git a/Examples/test-suite/d/preproc_constants_c_runme.1.d b/Examples/test-suite/d/preproc_constants_c_runme.1.d
c531d3
index 2b349af..b79ee3b 100644
c531d3
--- a/Examples/test-suite/d/preproc_constants_c_runme.1.d
c531d3
+++ b/Examples/test-suite/d/preproc_constants_c_runme.1.d
c531d3
@@ -61,6 +61,7 @@ void main() {
c531d3
   static assert(is(int == typeof(EXPR_LAND())));
c531d3
   static assert(is(int == typeof(EXPR_LOR())));
c531d3
   static assert(is(double == typeof(EXPR_CONDITIONAL())));
c531d3
+  static assert(is(double == typeof(EXPR_MIXED1())));
c531d3
   static assert(is(int == typeof(EXPR_WCHAR_MAX())));
c531d3
   static assert(is(int == typeof(EXPR_WCHAR_MIN())));
c531d3
 }
c531d3
diff --git a/Examples/test-suite/d/preproc_constants_c_runme.2.d b/Examples/test-suite/d/preproc_constants_c_runme.2.d
c531d3
index 1bac525..260bf8d 100644
c531d3
--- a/Examples/test-suite/d/preproc_constants_c_runme.2.d
c531d3
+++ b/Examples/test-suite/d/preproc_constants_c_runme.2.d
c531d3
@@ -61,6 +61,7 @@ void main() {
c531d3
   static assert(is(int == typeof(EXPR_LAND())));
c531d3
   static assert(is(int == typeof(EXPR_LOR())));
c531d3
   static assert(is(double == typeof(EXPR_CONDITIONAL())));
c531d3
+  static assert(is(double == typeof(EXPR_MIXED1())));
c531d3
   static assert(is(int == typeof(EXPR_WCHAR_MAX())));
c531d3
   static assert(is(int == typeof(EXPR_WCHAR_MIN())));
c531d3
 }
c531d3
diff --git a/Examples/test-suite/d/preproc_constants_runme.1.d b/Examples/test-suite/d/preproc_constants_runme.1.d
c531d3
index f743f48..84a99c8 100644
c531d3
--- a/Examples/test-suite/d/preproc_constants_runme.1.d
c531d3
+++ b/Examples/test-suite/d/preproc_constants_runme.1.d
c531d3
@@ -60,6 +60,7 @@ void main() {
c531d3
   static assert(is(bool == typeof(EXPR_LAND())));
c531d3
   static assert(is(bool == typeof(EXPR_LOR())));
c531d3
   static assert(is(double == typeof(EXPR_CONDITIONAL())));
c531d3
+  static assert(is(double == typeof(EXPR_MIXED1())));
c531d3
   static assert(is(int == typeof(EXPR_WCHAR_MAX())));
c531d3
   static assert(is(int == typeof(EXPR_WCHAR_MIN())));
c531d3
 }
c531d3
diff --git a/Examples/test-suite/d/preproc_constants_runme.2.d b/Examples/test-suite/d/preproc_constants_runme.2.d
c531d3
index 0d96c37..f6638f4 100644
c531d3
--- a/Examples/test-suite/d/preproc_constants_runme.2.d
c531d3
+++ b/Examples/test-suite/d/preproc_constants_runme.2.d
c531d3
@@ -60,6 +60,7 @@ void main() {
c531d3
   static assert(is(bool == typeof(EXPR_LAND())));
c531d3
   static assert(is(bool == typeof(EXPR_LOR())));
c531d3
   static assert(is(double == typeof(EXPR_CONDITIONAL())));
c531d3
+  static assert(is(double == typeof(EXPR_MIXED1())));
c531d3
   static assert(is(int == typeof(EXPR_WCHAR_MAX())));
c531d3
   static assert(is(int == typeof(EXPR_WCHAR_MIN())));
c531d3
 }
c531d3
diff --git a/Examples/test-suite/php/preproc_constants_c_runme.php b/Examples/test-suite/php/preproc_constants_c_runme.php
c531d3
index e59fe18..20868dc 100644
c531d3
--- a/Examples/test-suite/php/preproc_constants_c_runme.php
c531d3
+++ b/Examples/test-suite/php/preproc_constants_c_runme.php
c531d3
@@ -62,6 +62,7 @@ check::equal(gettype(preproc_constants_c::EXPR_OR), "integer", "preproc_constant
c531d3
 check::equal(gettype(preproc_constants_c::EXPR_LAND), "integer", "preproc_constants.EXPR_LAND has unexpected type");
c531d3
 check::equal(gettype(preproc_constants_c::EXPR_LOR), "integer", "preproc_constants.EXPR_LOR has unexpected type");
c531d3
 check::equal(gettype(preproc_constants_c::EXPR_CONDITIONAL), "double", "preproc_constants.EXPR_CONDITIONAL has unexpected type");
c531d3
+check::equal(gettype(preproc_constants_c::EXPR_MIXED1), "double", "preproc_constants.EXPR_MIXED1 has unexpected type");
c531d3
 check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type");
c531d3
 check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type");
c531d3
 
c531d3
diff --git a/Examples/test-suite/php/preproc_constants_runme.php b/Examples/test-suite/php/preproc_constants_runme.php
c531d3
index 8e117ea..ef32867 100644
c531d3
--- a/Examples/test-suite/php/preproc_constants_runme.php
c531d3
+++ b/Examples/test-suite/php/preproc_constants_runme.php
c531d3
@@ -63,5 +63,6 @@ check::equal(gettype(preproc_constants::EXPR_LOR), "boolean", "preproc_constants
c531d3
 check::equal(gettype(preproc_constants::EXPR_CONDITIONAL), "double", "preproc_constants.EXPR_CONDITIONAL has unexpected type");
c531d3
 check::equal(gettype(preproc_constants::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type");
c531d3
 check::equal(gettype(preproc_constants::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type");
c531d3
+check::equal(gettype(preproc_constants::EXPR_MIXED1), "integer", "preproc_constants.EXPR_MIXED1 has unexpected type");
c531d3
 
c531d3
 ?>
c531d3
diff --git a/Examples/test-suite/php5/preproc_constants_c_runme.php b/Examples/test-suite/php5/preproc_constants_c_runme.php
c531d3
index d978fab..d55d423 100644
c531d3
--- a/Examples/test-suite/php5/preproc_constants_c_runme.php
c531d3
+++ b/Examples/test-suite/php5/preproc_constants_c_runme.php
c531d3
@@ -62,6 +62,7 @@ check::equal(gettype(preproc_constants_c::EXPR_OR), "integer", "preproc_constant
c531d3
 check::equal(gettype(preproc_constants_c::EXPR_LAND), "integer", "preproc_constants.EXPR_LAND has unexpected type");
c531d3
 check::equal(gettype(preproc_constants_c::EXPR_LOR), "integer", "preproc_constants.EXPR_LOR has unexpected type");
c531d3
 check::equal(gettype(preproc_constants_c::EXPR_CONDITIONAL), "double", "preproc_constants.EXPR_CONDITIONAL has unexpected type");
c531d3
+check::equal(gettype(preproc_constants_c::EXPR_MIXED1), "double", "preproc_constants.EXPR_MIXED1 has unexpected type");
c531d3
 check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type");
c531d3
 check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type");
c531d3
 
c531d3
diff --git a/Examples/test-suite/php5/preproc_constants_runme.php b/Examples/test-suite/php5/preproc_constants_runme.php
c531d3
index 7527026..01137b0 100644
c531d3
--- a/Examples/test-suite/php5/preproc_constants_runme.php
c531d3
+++ b/Examples/test-suite/php5/preproc_constants_runme.php
c531d3
@@ -70,6 +70,7 @@ check::equal(gettype(preproc_constants::EXPR_LAND), "integer", "preproc_constant
c531d3
 check::equal(gettype(preproc_constants::EXPR_LOR), "integer", "preproc_constants.EXPR_LOR has unexpected type");
c531d3
 
c531d3
 check::equal(gettype(preproc_constants::EXPR_CONDITIONAL), "double", "preproc_constants.EXPR_CONDITIONAL has unexpected type");
c531d3
+check::equal(gettype(preproc_constants::EXPR_MIXED1), "double", "preproc_constants.EXPR_MIXED1 has unexpected type");
c531d3
 check::equal(gettype(preproc_constants::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type");
c531d3
 check::equal(gettype(preproc_constants::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type");
c531d3
 
c531d3
diff --git a/Examples/test-suite/preproc_constants.i b/Examples/test-suite/preproc_constants.i
c531d3
index 16b44c9..628cae1 100644
c531d3
--- a/Examples/test-suite/preproc_constants.i
c531d3
+++ b/Examples/test-suite/preproc_constants.i
c531d3
@@ -86,6 +86,7 @@
c531d3
 #define EXPR_LAND        0xFF && 1
c531d3
 #define EXPR_LOR         0xFF || 1
c531d3
 #define EXPR_CONDITIONAL true ? 2 : 2.2
c531d3
+#define EXPR_MIXED1      (0x80 + 11.1) - 1
c531d3
 
c531d3
 #define EXPR_WCHAR_MAX   (0x7fffffff + L'\0')
c531d3
 #define EXPR_WCHAR_MIN   (-EXPR_WCHAR_MAX - 1)
c531d3
diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
c531d3
index 273dadb..3df9896 100644
c531d3
--- a/Source/CParse/parser.y
c531d3
+++ b/Source/CParse/parser.y
c531d3
@@ -6338,6 +6338,7 @@ valexpr        : exprnum { $$ = $1; }
c531d3
 		       break;
c531d3
 		   }
c531d3
 		 }
c531d3
+		 $$.type = promote($2.type, $4.type);
c531d3
  	       }
c531d3
                | LPAREN expr pointer RPAREN expr %prec CAST {
c531d3
                  $$ = $5;
c531d3
-- 
c531d3
2.9.5
c531d3