]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/60223 - ICE with T{} in non-deduced context.
authorMarek Polacek <polacek@redhat.com>
Tue, 2 Jul 2019 00:22:37 +0000 (00:22 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 2 Jul 2019 00:22:37 +0000 (00:22 +0000)
* pt.c (unify): Allow COMPOUND_LITERAL_P in a non-deduced context.

* g++.dg/cpp0x/nondeduced1.C: New test.
* g++.dg/cpp0x/nondeduced2.C: New test.
* g++.dg/cpp0x/nondeduced3.C: New test.
* g++.dg/cpp0x/nondeduced4.C: New test.

From-SVN: r272917

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp0x/nondeduced1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/nondeduced2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/nondeduced3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/nondeduced4.C [new file with mode: 0644]

index fa0f93768ab42cd2025a94a7b991bd440fc9cdc7..50e187be21a9072157c14defc328f00de330d869 100644 (file)
@@ -1,3 +1,11 @@
+2019-07-01  Marek Polacek  <polacek@redhat.com>
+
+       Backported from mainline
+       2019-06-21  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/60223 - ICE with T{} in non-deduced context.
+       * pt.c (unify): Allow COMPOUND_LITERAL_P in a non-deduced context.
+
 2019-06-29  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
index 9b5e6576b7e14fb02d2e868b8d41305e8234830e..426700a7211b8fe0d3c7efee53ae18e51881c8ed 100644 (file)
@@ -22795,7 +22795,9 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict,
       /* An unresolved overload is a nondeduced context.  */
       if (is_overloaded_fn (parm) || type_unknown_p (parm))
        return unify_success (explain_p);
-      gcc_assert (EXPR_P (parm) || TREE_CODE (parm) == TRAIT_EXPR);
+      gcc_assert (EXPR_P (parm)
+                 || COMPOUND_LITERAL_P (parm)
+                 || TREE_CODE (parm) == TRAIT_EXPR);
     expr:
       /* We must be looking at an expression.  This can happen with
         something like:
@@ -22803,15 +22805,19 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict,
           template <int I>
           void foo(S<I>, S<I + 2>);
 
-        This is a "nondeduced context":
+        or
+
+          template<typename T>
+          void foo(A<T, T{}>);
+
+        This is a "non-deduced context":
 
           [deduct.type]
 
-          The nondeduced contexts are:
+          The non-deduced contexts are:
 
-          --A type that is a template-id in which one or more of
-            the template-arguments is an expression that references
-            a template-parameter.
+          --A non-type template argument or an array bound in which
+            a subexpression references a template parameter.
 
         In these cases, we assume deduction succeeded, but don't
         actually infer any unifications.  */
diff --git a/gcc/testsuite/g++.dg/cpp0x/nondeduced1.C b/gcc/testsuite/g++.dg/cpp0x/nondeduced1.C
new file mode 100644 (file)
index 0000000..067079e
--- /dev/null
@@ -0,0 +1,16 @@
+// PR c++/60223
+// { dg-do compile { target c++11 } }
+
+template<typename T, T = T{}>
+struct A { };
+
+template<typename T>
+void foo(A<T> a);
+
+void bar()
+{
+  foo(A<char, char{}>());
+  foo(A<char>());
+  foo<>(A<char>());
+  foo<>(A<char, char{}>());
+}
diff --git a/gcc/testsuite/g++.dg/cpp0x/nondeduced2.C b/gcc/testsuite/g++.dg/cpp0x/nondeduced2.C
new file mode 100644 (file)
index 0000000..3f96fe4
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/60223
+// { dg-do compile { target c++11 } }
+
+template<typename T, T>
+struct A { };
+
+template<typename T>
+void foo(A<T, T{}>);
+
+void bar()
+{
+  foo(A<char, char{}>());
+  foo<>(A<char, char{}>());
+}
diff --git a/gcc/testsuite/g++.dg/cpp0x/nondeduced3.C b/gcc/testsuite/g++.dg/cpp0x/nondeduced3.C
new file mode 100644 (file)
index 0000000..d943dce
--- /dev/null
@@ -0,0 +1,16 @@
+// PR c++/60223
+// { dg-do compile { target c++11 } }
+
+template<typename T, T = T{1}>
+struct A { };
+
+template<typename T>
+void foo(A<T> a);
+
+void bar()
+{
+  foo(A<char>());
+  foo(A<char, char{1}>());
+  foo<>(A<char>());
+  foo<>(A<char, char{1}>());
+}
diff --git a/gcc/testsuite/g++.dg/cpp0x/nondeduced4.C b/gcc/testsuite/g++.dg/cpp0x/nondeduced4.C
new file mode 100644 (file)
index 0000000..818034c
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/60223
+// { dg-do compile { target c++11 } }
+
+template<typename T>
+struct A { };
+
+template<typename T>
+void foo(A<T>, T = T{});
+
+void bar()
+{
+  foo(A<int>());
+}