re PR c++/85112 (ICE with invalid constexpr)
authorPaolo Carlini <paolo.carlini@oracle.com>
Mon, 16 Apr 2018 08:31:23 +0000 (08:31 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 16 Apr 2018 08:31:23 +0000 (08:31 +0000)
2018-04-16  Paolo Carlini  <paolo.carlini@oracle.com>
    Jason Merrill  <jason@redhat.com>

PR c++/85112
* convert.c (convert_to_integer_1): Use direct recursion for
enumeral types and types with a precision less than the number
of bits in their mode.

/testsuite
2018-04-16  Paolo Carlini  <paolo.carlini@oracle.com>
    Jason Merrill  <jason@redhat.com>

PR c++/85112
* g++.dg/cpp0x/pr85112.C: New.

Co-Authored-By: Jason Merrill <jason@redhat.com>
From-SVN: r259397

gcc/ChangeLog
gcc/convert.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/pr85112.C [new file with mode: 0644]

index a04b68f7524e651d898e8559604296b0baeebb72..3a82dfec269d9f86f728fa63eeb71950a9b43404 100644 (file)
@@ -1,3 +1,11 @@
+2018-04-16  Paolo Carlini  <paolo.carlini@oracle.com>
+           Jason Merrill  <jason@redhat.com>
+
+       PR c++/85112
+       * convert.c (convert_to_integer_1): Use direct recursion for
+       enumeral types and types with a precision less than the number
+       of bits in their mode.
+
 2018-04-16  Julia Koval  <julia.koval@intel.com>
 
        PR target/84413
index 8c8931f40ed284d80d69eb3c4a23a76f18678073..68705f3e9b09c5d0e6bae0ba1c7bca0db7107980 100644 (file)
@@ -741,8 +741,10 @@ convert_to_integer_1 (tree type, tree expr, bool dofold)
       else if (TREE_CODE (type) == ENUMERAL_TYPE
               || maybe_ne (outprec, GET_MODE_PRECISION (TYPE_MODE (type))))
        {
-         expr = convert (lang_hooks.types.type_for_mode
-                         (TYPE_MODE (type), TYPE_UNSIGNED (type)), expr);
+         expr
+           = convert_to_integer_1 (lang_hooks.types.type_for_mode
+                                   (TYPE_MODE (type), TYPE_UNSIGNED (type)),
+                                   expr, dofold);
          return maybe_fold_build1_loc (dofold, loc, NOP_EXPR, type, expr);
        }
 
index 70d1c3c1fade6df49e608f80545b928fb2be58b7..8806b95bb3f486bb04840ca52b20f7148319e5ca 100644 (file)
@@ -1,3 +1,9 @@
+2018-04-16  Paolo Carlini  <paolo.carlini@oracle.com>
+           Jason Merrill  <jason@redhat.com>
+
+       PR c++/85112
+       * g++.dg/cpp0x/pr85112.C: New.
+
 2018-04-15  Bill Schmidt  <wschmidt@linux.ibm.com>
 
        PR testsuite/85326
diff --git a/gcc/testsuite/g++.dg/cpp0x/pr85112.C b/gcc/testsuite/g++.dg/cpp0x/pr85112.C
new file mode 100644 (file)
index 0000000..13d25be
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/85112
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  int m;
+  int n : 4;
+};
+
+int i;  // { dg-message "not const" }
+
+void foo()
+{
+  constexpr int j = i;  // { dg-error "not usable" }
+  A a;
+  a.n = j;
+}