]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
/cp
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 14 Aug 2013 21:42:54 +0000 (21:42 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 14 Aug 2013 21:42:54 +0000 (21:42 +0000)
2013-08-14  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/51912
* cp-tree.h (LOOKUP_NO_NON_INTEGRAL): Add.
* decl.c (case_conversion): Use it.
* call.c (standard_conversion): Likewise.
(implicit_conversion): Adjust.

/testsuite
2013-08-14  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/51912
* g++.dg/cpp0x/enum28.C: New.
* g++.dg/cpp0x/enum15.C: Adjust.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@201754 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/enum15.C
gcc/testsuite/g++.dg/cpp0x/enum28.C [new file with mode: 0644]

index 6dd0cd8dfbcb0368ccfd4c920948dd2f4ae5d34b..502eecb812e1a6cc7f3444d0dd3ad07b2b2b11d3 100644 (file)
@@ -1,3 +1,11 @@
+2013-08-14  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/51912
+       * cp-tree.h (LOOKUP_NO_NON_INTEGRAL): Add.
+       * decl.c (case_conversion): Use it.
+       * call.c (standard_conversion): Likewise.
+       (implicit_conversion): Adjust.
+
 2013-08-13  Adam Butcher  <adam@jessamine.co.uk>
 
        * pt.c: Grammar fix in comments ("it's" to "its").
index 56346063f3db7ce2dc2f4a991b191605a0beb35a..e493a7947be5c67bd1a4a33f6a147fbef11a69d9 100644 (file)
@@ -1314,7 +1314,8 @@ standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
   /* As an extension, allow conversion to complex type.  */
   else if (ARITHMETIC_TYPE_P (to))
     {
-      if (! (INTEGRAL_CODE_P (fcode) || fcode == REAL_TYPE)
+      if (! (INTEGRAL_CODE_P (fcode)
+            || (fcode == REAL_TYPE && !(flags & LOOKUP_NO_NON_INTEGRAL)))
           || SCOPED_ENUM_P (from))
        return NULL;
       conv = build_conv (ck_std, to, conv);
@@ -1681,7 +1682,7 @@ implicit_conversion (tree to, tree from, tree expr, bool c_cast_p,
      resolution, or after we've chosen one.  */
   flags &= (LOOKUP_ONLYCONVERTING|LOOKUP_NO_CONVERSION|LOOKUP_COPY_PARM
            |LOOKUP_NO_TEMP_BIND|LOOKUP_NO_RVAL_BIND|LOOKUP_PREFER_RVALUE
-           |LOOKUP_NO_NARROWING|LOOKUP_PROTECT);
+           |LOOKUP_NO_NARROWING|LOOKUP_PROTECT|LOOKUP_NO_NON_INTEGRAL);
 
   /* FIXME: actually we don't want warnings either, but we can't just
      have 'complain &= ~(tf_warning|tf_error)' because it would cause
index 86727398fbc7c13fcb1a2acd9f8c145dbb737e1a..51dab8aa4f34aafc85b63aaf5b43f1ed60a5197d 100644 (file)
@@ -4510,6 +4510,8 @@ enum overload_flags { NO_SPECIAL = 0, DTOR_FLAG, TYPENAME_FLAG };
 #define LOOKUP_EXPLICIT_TMPL_ARGS (LOOKUP_ALREADY_DIGESTED << 1)
 /* Like LOOKUP_NO_TEMP_BIND, but also prevent binding to xvalues.  */
 #define LOOKUP_NO_RVAL_BIND (LOOKUP_EXPLICIT_TMPL_ARGS << 1)
+/* Used by case_conversion to disregard non-integral conversions.  */
+#define LOOKUP_NO_NON_INTEGRAL (LOOKUP_NO_RVAL_BIND << 1)
 
 #define LOOKUP_NAMESPACES_ONLY(F)  \
   (((F) & LOOKUP_PREFER_NAMESPACES) && !((F) & LOOKUP_PREFER_TYPES))
index 16f751c8ff12905c563a0b86fb64b7ba2e0a3ce4..95d5bbda785e53ec6c6915abc06df5ce3776fa7e 100644 (file)
@@ -3103,7 +3103,9 @@ case_conversion (tree type, tree value)
     {
       if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
        type = type_promotes_to (type);
-      value = perform_implicit_conversion (type, value, tf_warning_or_error);
+      value = (perform_implicit_conversion_flags
+              (type, value, tf_warning_or_error,
+               LOOKUP_IMPLICIT | LOOKUP_NO_NON_INTEGRAL));
     }
   return cxx_constant_value (value);
 }
index 72fcd6087ce2873d3d8a350ef128d7ffa67c3c67..9b115a48df313b2ea4303d52d2d56728f660ba2b 100644 (file)
@@ -1,3 +1,9 @@
+2013-08-14  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/51912
+       * g++.dg/cpp0x/enum28.C: New.
+       * g++.dg/cpp0x/enum15.C: Adjust.
+
 2013-08-14  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
 
        PR target/57949
index d653216498ed4ae7b023825c7b417d1ea61bfdb2..1d33f90290f6db7eeb7c0a289dcfb07667d65528 100644 (file)
@@ -15,6 +15,6 @@ void foo (A a, int i)
     {
     case A::Val0: break;       // { dg-error "" }
     case 1: break;
-    case 2.0: break;
+    case 2.0: break;            // { dg-error "" }
     }
 }
diff --git a/gcc/testsuite/g++.dg/cpp0x/enum28.C b/gcc/testsuite/g++.dg/cpp0x/enum28.C
new file mode 100644 (file)
index 0000000..3967699
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/51912
+// { dg-do compile { target c++11 } }
+
+constexpr double g() { return 2.0; }
+
+void f(int i)
+{
+  switch (i)
+    {
+    case 1.0:;    // { dg-error "could not convert" }
+    }
+
+  switch (i)
+    {
+    case g():;    // { dg-error "could not convert" }
+    }
+}