re PR c++/58882 (ICE with invalid C99 style designated initializers)
authorPaolo Carlini <paolo@gcc.gnu.org>
Mon, 15 Dec 2014 16:16:29 +0000 (16:16 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 15 Dec 2014 16:16:29 +0000 (16:16 +0000)
/cp
2014-12-15  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/58882
* decl.c (check_array_designated_initializer): Diagnose gracefully
C99 designators which aren't integral constant-expressions; allow
constexpr user-defined type conversion operators.

/testsuite
2014-12-15  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/58882
* g++.dg/ext/desig8.C: New.
* g++.dg/cpp0x/desig1.C: Likewise.

From-SVN: r218752

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/desig1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/desig8.C [new file with mode: 0644]

index 576610deed0d5c103cf3f82d5abd0d94d2eb5179..4eb762c91abf1289c57ba5030a033044c95e39b0 100644 (file)
@@ -1,3 +1,10 @@
+2014-12-15  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/58882
+       * decl.c (check_array_designated_initializer): Diagnose gracefully
+       C99 designators which aren't integral constant-expressions; allow
+       constexpr user-defined type conversion operators.
+
 2014-12-12  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/59628
index 5ed9b2c216a58933e50bde3cb2af3c185a889f46..d47865287a83c2ded66aa424a465b307d842990c 100644 (file)
@@ -4996,18 +4996,22 @@ check_array_designated_initializer (constructor_elt *ce,
          return false;
        }
 
-      ce->index = cxx_constant_value (ce->index);
-
-      if (TREE_CODE (ce->index) == INTEGER_CST)
+      tree ce_index = build_expr_type_conversion (WANT_INT | WANT_ENUM,
+                                                 ce->index, true);
+      if (ce_index
+         && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ce_index))
+         && (TREE_CODE (ce_index = maybe_constant_value (ce_index))
+             == INTEGER_CST))
        {
          /* A C99 designator is OK if it matches the current index.  */
-         if (wi::eq_p (ce->index, index))
+         if (wi::eq_p (ce_index, index))
            return true;
          else
            sorry ("non-trivial designated initializers not supported");
        }
       else
-       gcc_unreachable ();
+       error ("C99 designator %qE is not an integral constant-expression",
+              ce->index);
 
       return false;
     }
index 808f5a2ccde3073ac02d617837cb9c19c9f0f698..75e15d034c7809aeffb91ef55a36bafeb4a12f80 100644 (file)
@@ -1,3 +1,9 @@
+2014-12-15  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/58882
+       * g++.dg/ext/desig8.C: New.
+       * g++.dg/cpp0x/desig1.C: Likewise.
+
 2014-12-15  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/63727
@@ -23,8 +29,9 @@
        instead of %e in regexps trying to match 32-bit GPR.
        * gcc.target/i386/avx512f-vpbroadcastd-1.c: Likewise.
        * gcc.target/i386/avx512vl-vpbroadcastd-1.c: Likewise.
-       * gcc.target/i386/avx512vl-vmovdqa64-1.c: Restrict some scan-assembler-times
-       lines to nonpic targets only.  Fix up \[^\n^x^y\] to \[^\nxy\].
+       * gcc.target/i386/avx512vl-vmovdqa64-1.c: Restrict some
+       scan-assembler-times lines to nonpic targets only.
+       Fix up \[^\n^x^y\] to \[^\nxy\].
 
 2014-12-15  Paolo Carlini  <paolo.carlini@oracle.com>
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/desig1.C b/gcc/testsuite/g++.dg/cpp0x/desig1.C
new file mode 100644 (file)
index 0000000..cc52730
--- /dev/null
@@ -0,0 +1,27 @@
+// PR c++/58882
+// { dg-do compile { target c++11 } }
+
+struct A
+{
+  constexpr operator int() const { return 0; }
+};
+
+int a[] = { [A()] = 0 };
+
+enum E { e0 };
+
+struct B
+{
+  constexpr operator E() const { return E::e0; }
+};
+
+int b[] = { [B()] = 0 };
+
+enum class SE { se0 };
+
+struct C
+{
+  constexpr operator SE() const { return SE::se0; }
+};
+
+int c[] = { [C()] = 0 }; // { dg-error "integral constant-expression" }
diff --git a/gcc/testsuite/g++.dg/ext/desig8.C b/gcc/testsuite/g++.dg/ext/desig8.C
new file mode 100644 (file)
index 0000000..98e7bfd
--- /dev/null
@@ -0,0 +1,3 @@
+// PR c++/58882
+
+int a[] = { [0.] = 0 }; // { dg-error "integral constant-expression" }