[PR c++/71965] silence multi-dim array init sorry without tf_error
authorAlexandre Oliva <aoliva@redhat.com>
Wed, 21 Mar 2018 22:08:34 +0000 (22:08 +0000)
committerAlexandre Oliva <aoliva@gcc.gnu.org>
Wed, 21 Mar 2018 22:08:34 +0000 (22:08 +0000)
We shouldn't substitute templates into short-circuited-out concepts
constraints, but we do, and to add insult to injury, we issue a
sorry() error when a concept that shouldn't even have been substituted
attempts to perform a multi-dimensional array initialization with a
new{} expression.

Although fixing the requirements short-circuiting is probably too
risky at this point, we can get closer to the intended effect by
silencing that sorry just as we silence other errors.

for  gcc/cp/ChangeLog

PR c++/71965
* init.c (build_vec_init): Silence error, former sorry,
without tf_error.

for  gcc/testsuite/ChangeLog

PR c++/71965
* g++.dg/concepts/pr71965.C: New.

From-SVN: r258749

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/concepts/pr71965.C [new file with mode: 0644]

index 233b57e2620005db621eb1b50881b925c00a5963..1271e5dca21752c75fb4f3a3ed9407381dc26603 100644 (file)
@@ -1,5 +1,9 @@
 2018-03-21  Alexandre Oliva <aoliva@redhat.com>
 
+       PR c++/71965
+       * init.c (build_vec_init): Silence error, former sorry,
+       without tf_error.
+
        PR c++/84610
        PR c++/84642
        * parser.c (abort_fully_implicit_template_p): New.
index 15cee17c780c7c60505c4ed6aad8a173f8e3ad6f..3215c23855406064ad642e8487f234cff0ce3816 100644 (file)
@@ -4384,12 +4384,17 @@ build_vec_init (tree base, tree maxindex, tree init,
       else if (TREE_CODE (type) == ARRAY_TYPE)
        {
          if (init && !BRACE_ENCLOSED_INITIALIZER_P (init))
-           sorry
-             ("cannot initialize multi-dimensional array with initializer");
-         elt_init = build_vec_init (build1 (INDIRECT_REF, type, base),
-                                    0, init,
-                                    explicit_value_init_p,
-                                    0, complain);
+           {
+             if ((complain & tf_error))
+               error_at (loc, "array must be initialized "
+                         "with a brace-enclosed initializer");
+             elt_init = error_mark_node;
+           }
+         else
+           elt_init = build_vec_init (build1 (INDIRECT_REF, type, base),
+                                      0, init,
+                                      explicit_value_init_p,
+                                      0, complain);
        }
       else if (explicit_value_init_p)
        {
@@ -4449,7 +4454,7 @@ build_vec_init (tree base, tree maxindex, tree init,
        }
 
       current_stmt_tree ()->stmts_are_full_exprs_p = 1;
-      if (elt_init)
+      if (elt_init && !errors)
        finish_expr_stmt (elt_init);
       current_stmt_tree ()->stmts_are_full_exprs_p = 0;
 
index 45705c0eacbae94879d7f4356f494393f00432e6..ea5437a7a17c1063a0597fcca95a065dde47c005 100644 (file)
@@ -1,5 +1,8 @@
 2018-03-21  Alexandre Oliva <aoliva@redhat.com>
 
+       PR c++/71965
+       * g++.dg/concepts/pr71965.C: New.
+
        PR c++/84610
        PR c++/84642
        * g++.dg/cpp0x/pr84610.C: New.
diff --git a/gcc/testsuite/g++.dg/concepts/pr71965.C b/gcc/testsuite/g++.dg/concepts/pr71965.C
new file mode 100644 (file)
index 0000000..6bfaef1
--- /dev/null
@@ -0,0 +1,27 @@
+// { dg-do compile { target c++14 } }
+// { dg-options "-fconcepts" }
+
+template <class T>
+concept bool Destructible() {
+    return false;
+}
+
+template <class T, class...Args>
+concept bool ConstructibleObject =
+    // Concept evaluation should short-circuit even the template
+    // substitution, so we shouldn't even substitute into the requires
+    // constraint and the unimplemented multi-dimensional new T{...}
+    // initialization.  ATM we do, but as long as we don't output the
+    // sorry() message we used to for such constructs when asked not
+    // to issue errors, this shouldn't be a problem for this and
+    // similar cases.
+    Destructible<T>() && requires (Args&&...args) {
+        new T{ (Args&&)args... };
+    };
+
+int main() {
+    using T = int[2][2];
+    // GCC has not implemented initialization of multi-dimensional
+    // arrays with new{} expressions.
+    static_assert(!ConstructibleObject<T, T>);
+}