typeck.c (build_static_cast): Allow enum to enum conversions as per DR 128.
authorNathan Sidwell <nathan@codesourcery.com>
Fri, 2 Mar 2001 11:48:38 +0000 (11:48 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Fri, 2 Mar 2001 11:48:38 +0000 (11:48 +0000)
cp:
* typeck.c (build_static_cast): Allow enum to enum conversions
as per DR 128.
testsuite:
* g++.old-deja/g++.other/enum3.C: New test.

From-SVN: r40187

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.old-deja/g++.other/enum3.C [new file with mode: 0644]

index af98592afefc8afe0d4d01506b29a940a1eccc75..389b9fc2dd41dda3f9fef0e901d178efe357899e 100644 (file)
@@ -1,3 +1,8 @@
+2001-03-02  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * typeck.c (build_static_cast): Allow enum to enum conversions
+       as per DR 128.
+
 2001-03-02  Nathan Sidwell  <nathan@codesourcery.com>
 
        * class.c (check_field_decls): Pointers to member do not a
index f0d70ce4f47fe2f8bcce9a7309479085d2feb0e8..8b873422789f02b63301f20fb4d5813e6d3a41e1 100644 (file)
@@ -5093,6 +5093,13 @@ build_static_cast (type, expr)
           && TREE_CODE (type) != FUNCTION_TYPE
           && can_convert (intype, strip_all_pointer_quals (type)))
     ok = 1;
+  else if (TREE_CODE (intype) == ENUMERAL_TYPE
+           && TREE_CODE (type) == ENUMERAL_TYPE)
+    /* DR 128: "A value of integral _or enumeration_ type can be explicitly
+       converted to an enumeration type."
+       The integral to enumeration will be accepted by the previous clause.
+       We need to explicitly check for enumeration to enumeration.  */
+    ok = 1;
 
   /* [expr.static.cast]
 
index e0b9178076d5f660f49880b4d33808c81054d803..94aa89216e9951e9884394820dc5ed7febd927a9 100644 (file)
@@ -1,3 +1,7 @@
+2001-03-02  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * g++.old-deja/g++.other/enum3.C: New test.
+
 2001-03-02  Nathan Sidwell  <nathan@codesourcery.com>
 
        * g++.old-deja/g++.other/pod1.C: New test.
diff --git a/gcc/testsuite/g++.old-deja/g++.other/enum3.C b/gcc/testsuite/g++.old-deja/g++.other/enum3.C
new file mode 100644 (file)
index 0000000..c4303f6
--- /dev/null
@@ -0,0 +1,14 @@
+// Build don't link:
+
+// Copyright (C) 2001 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 28 Feb 2001 <nathan@codesourcery.com>
+
+// Bug 338 and DR 128. Allow static cast to convert between enums.
+
+enum E1 {e1};
+enum E2 {e2};
+
+E2 Foo (E1 e)
+{
+  return static_cast <E2> (e);
+}