Index: cp/ChangeLog
authorGeoffrey Keating <geoffk@apple.com>
Thu, 24 Mar 2005 23:33:56 +0000 (23:33 +0000)
committerGeoffrey Keating <geoffk@gcc.gnu.org>
Thu, 24 Mar 2005 23:33:56 +0000 (23:33 +0000)
2005-03-24  Geoffrey Keating  <geoffk@apple.com>

* typeck.c (build_static_cast_1): Allow scalar_cast between
any integral, floating, or enumeration type.

Index: testsuite/ChangeLog
2005-03-24  Geoffrey Keating  <geoffk@apple.com>

* g++.dg/expr/cast3.C: New.

From-SVN: r97019

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/expr/cast3.C [new file with mode: 0644]

index ae435c1a5cf13af5a83761fcebd164ad7c82a3d2..d7697372ecdfd292b94c367fd370242d120ff22c 100644 (file)
@@ -1,3 +1,8 @@
+2005-03-24  Geoffrey Keating  <geoffk@apple.com>
+
+       * typeck.c (build_static_cast_1): Allow scalar_cast between
+       any integral, floating, or enumeration type.
+
 2005-03-24  Steven Bosscher  <stevenb@suse.de>
 
        * typeck.c (comptypes): First determine if the types are compatible
index e2cb1f8bb104dc2d7f45aef93bcb1973372f2d54..a3bf1c0281f7fd802cb60db0adb805342138fcba 100644 (file)
@@ -4624,13 +4624,15 @@ build_static_cast_1 (tree type, tree expr, bool c_cast_p,
      promotions, floating point promotion, integral conversions,
      floating point conversions, floating-integral conversions,
      pointer conversions, and pointer to member conversions.  */
-  if ((ARITHMETIC_TYPE_P (type) && ARITHMETIC_TYPE_P (intype))
-      /* DR 128
-
-         A value of integral _or enumeration_ type can be explicitly
-        converted to an enumeration type.  */
-      || (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
-         && INTEGRAL_OR_ENUMERATION_TYPE_P (intype)))
+  /* DR 128
+     
+     A value of integral _or enumeration_ type can be explicitly
+     converted to an enumeration type.  */
+  /* The effect of all that is that any conversion between any two
+     types which are integral, floating, or enumeration types can be
+     performed.  */
+  if ((INTEGRAL_TYPE_P (type) || SCALAR_FLOAT_TYPE_P (type))
+      && (INTEGRAL_TYPE_P (intype) || SCALAR_FLOAT_TYPE_P (intype)))
     {
       expr = ocp_convert (type, expr, CONV_C_CAST, LOOKUP_NORMAL);
 
index 260a212c9165dbe109b2e2af67c1e3ee983fe019..0fe028909af150585ffe093b86d650a14cd06ea2 100644 (file)
@@ -1,3 +1,7 @@
+2005-03-24  Geoffrey Keating  <geoffk@apple.com>
+
+       * g++.dg/expr/cast3.C: New.
+
 2005-03-24  David Edelsohn  <edelsohn@gnu.org>
 
        * gcc.c-torture/execute/20020720-1.x: XFAIL for all powerpc and
diff --git a/gcc/testsuite/g++.dg/expr/cast3.C b/gcc/testsuite/g++.dg/expr/cast3.C
new file mode 100644 (file)
index 0000000..2ca56c2
--- /dev/null
@@ -0,0 +1,22 @@
+// { dg-do compile }
+
+enum MyState
+{
+        QUIT = 0,
+        START,
+        STOP,
+        PAUSE
+};
+
+double GetDouble()
+{
+        return 1.0;
+}
+
+int main()
+{
+        MyState the_state;
+
+        the_state = (MyState)GetDouble(); // { dg-bogus "invalid cast" }
+        return 0;
+}