public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Backport PR90505 fix to 9
@ 2020-03-04 21:03 Marek Polacek
  2020-03-04 22:23 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2020-03-04 21:03 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

While backporting our 90505 fix to 9 I noticed a bunch of concepts regressions.
Fortunately I think the following variant of the fix is safe and still fixes
the deduction issue.  In 9, we want to reject 'auto' when tf_partial before
returning cp_build_qualified_type_real for TEMPLATE_TYPE_PARM and similar.
And then to fix 90505, return early before reducing the template level.

The difference is caused by the huge concepts merge, so it's tough to figure
out what specific change caused it.

Bootstrapped/regtested on x86_64-linux, ok for 9?

2020-03-04  Jason Merrill  <jason@redhat.com>
	    Marek Polacek  <polacek@redhat.com>

	PR c++/90505 - mismatch in template argument deduction.
	* pt.c (tsubst): Don't reduce the template level of template
	parameters when tf_partial.

	* g++.dg/template/deduce4.C: New test.
	* g++.dg/template/deduce5.C: New test.
	* g++.dg/template/deduce6.C: New test.
	* g++.dg/template/deduce7.C: New test.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index f233e78cc45..2de9036b647 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -14630,6 +14630,11 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
 	     about the template parameter in question.  */
 	  return t;
 
+	/* Like with 'auto', don't reduce the level of template parameters
+	   to avoid mismatches when deducing their types.  */
+	if (complain & tf_partial)
+	  return t;
+
 	/* If we get here, we must have been looking at a parm for a
 	   more deeply nested template.  Make a new version of this
 	   template parameter, but with a lower level.  */
diff --git a/gcc/testsuite/g++.dg/template/deduce4.C b/gcc/testsuite/g++.dg/template/deduce4.C
new file mode 100644
index 00000000000..e2c165dc788
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/deduce4.C
@@ -0,0 +1,17 @@
+// PR c++/90505 - mismatch in template argument deduction.
+// { dg-do compile }
+
+template <typename T>
+struct S {
+  template <typename U, typename V>
+  static void foo(V) { }
+
+  void bar () { foo<int>(10); }
+};
+
+void
+test ()
+{
+  S<int> s;
+  s.bar ();
+}
diff --git a/gcc/testsuite/g++.dg/template/deduce5.C b/gcc/testsuite/g++.dg/template/deduce5.C
new file mode 100644
index 00000000000..9d382bfe03a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/deduce5.C
@@ -0,0 +1,17 @@
+// PR c++/90505 - mismatch in template argument deduction.
+// { dg-do compile { target c++11 } }
+
+template <typename T>
+struct S {
+  template <typename U, typename V = void>
+  static void foo(U) { }
+
+  void bar () { foo<int>(10); }
+};
+
+void
+test ()
+{
+  S<int> s;
+  s.bar ();
+}
diff --git a/gcc/testsuite/g++.dg/template/deduce6.C b/gcc/testsuite/g++.dg/template/deduce6.C
new file mode 100644
index 00000000000..8fee6124f5a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/deduce6.C
@@ -0,0 +1,17 @@
+// PR c++/90505 - mismatch in template argument deduction.
+// { dg-do compile { target c++11 } }
+
+template <typename T>
+struct S {
+  template <typename U = int, typename V>
+  static void foo(V) { }
+
+  void bar () { foo<>(10); }
+};
+
+void
+test ()
+{
+  S<int> s;
+  s.bar ();
+}
diff --git a/gcc/testsuite/g++.dg/template/deduce7.C b/gcc/testsuite/g++.dg/template/deduce7.C
new file mode 100644
index 00000000000..fbc28e5150d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/deduce7.C
@@ -0,0 +1,10 @@
+// PR c++/90505 - mismatch in template argument deduction.
+// { dg-do compile { target c++11 } }
+
+template <typename> class a {
+  using b = int;
+  using c = int;
+  b d;
+  void e() { g<c>(d); }
+  template <typename... f> static void g(f...);
+};

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c++: Backport PR90505 fix to 9
  2020-03-04 21:03 [PATCH] c++: Backport PR90505 fix to 9 Marek Polacek
@ 2020-03-04 22:23 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2020-03-04 22:23 UTC (permalink / raw)
  To: Marek Polacek, GCC Patches

On 3/4/20 4:02 PM, Marek Polacek wrote:
> While backporting our 90505 fix to 9 I noticed a bunch of concepts regressions.
> Fortunately I think the following variant of the fix is safe and still fixes
> the deduction issue.  In 9, we want to reject 'auto' when tf_partial before
> returning cp_build_qualified_type_real for TEMPLATE_TYPE_PARM and similar.
> And then to fix 90505, return early before reducing the template level.
> 
> The difference is caused by the huge concepts merge, so it's tough to figure
> out what specific change caused it.
> 
> Bootstrapped/regtested on x86_64-linux, ok for 9?

OK.

> 2020-03-04  Jason Merrill  <jason@redhat.com>
> 	    Marek Polacek  <polacek@redhat.com>
> 
> 	PR c++/90505 - mismatch in template argument deduction.
> 	* pt.c (tsubst): Don't reduce the template level of template
> 	parameters when tf_partial.
> 
> 	* g++.dg/template/deduce4.C: New test.
> 	* g++.dg/template/deduce5.C: New test.
> 	* g++.dg/template/deduce6.C: New test.
> 	* g++.dg/template/deduce7.C: New test.
> 
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index f233e78cc45..2de9036b647 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -14630,6 +14630,11 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
>   	     about the template parameter in question.  */
>   	  return t;
>   
> +	/* Like with 'auto', don't reduce the level of template parameters
> +	   to avoid mismatches when deducing their types.  */
> +	if (complain & tf_partial)
> +	  return t;
> +
>   	/* If we get here, we must have been looking at a parm for a
>   	   more deeply nested template.  Make a new version of this
>   	   template parameter, but with a lower level.  */
> diff --git a/gcc/testsuite/g++.dg/template/deduce4.C b/gcc/testsuite/g++.dg/template/deduce4.C
> new file mode 100644
> index 00000000000..e2c165dc788
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/deduce4.C
> @@ -0,0 +1,17 @@
> +// PR c++/90505 - mismatch in template argument deduction.
> +// { dg-do compile }
> +
> +template <typename T>
> +struct S {
> +  template <typename U, typename V>
> +  static void foo(V) { }
> +
> +  void bar () { foo<int>(10); }
> +};
> +
> +void
> +test ()
> +{
> +  S<int> s;
> +  s.bar ();
> +}
> diff --git a/gcc/testsuite/g++.dg/template/deduce5.C b/gcc/testsuite/g++.dg/template/deduce5.C
> new file mode 100644
> index 00000000000..9d382bfe03a
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/deduce5.C
> @@ -0,0 +1,17 @@
> +// PR c++/90505 - mismatch in template argument deduction.
> +// { dg-do compile { target c++11 } }
> +
> +template <typename T>
> +struct S {
> +  template <typename U, typename V = void>
> +  static void foo(U) { }
> +
> +  void bar () { foo<int>(10); }
> +};
> +
> +void
> +test ()
> +{
> +  S<int> s;
> +  s.bar ();
> +}
> diff --git a/gcc/testsuite/g++.dg/template/deduce6.C b/gcc/testsuite/g++.dg/template/deduce6.C
> new file mode 100644
> index 00000000000..8fee6124f5a
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/deduce6.C
> @@ -0,0 +1,17 @@
> +// PR c++/90505 - mismatch in template argument deduction.
> +// { dg-do compile { target c++11 } }
> +
> +template <typename T>
> +struct S {
> +  template <typename U = int, typename V>
> +  static void foo(V) { }
> +
> +  void bar () { foo<>(10); }
> +};
> +
> +void
> +test ()
> +{
> +  S<int> s;
> +  s.bar ();
> +}
> diff --git a/gcc/testsuite/g++.dg/template/deduce7.C b/gcc/testsuite/g++.dg/template/deduce7.C
> new file mode 100644
> index 00000000000..fbc28e5150d
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/deduce7.C
> @@ -0,0 +1,10 @@
> +// PR c++/90505 - mismatch in template argument deduction.
> +// { dg-do compile { target c++11 } }
> +
> +template <typename> class a {
> +  using b = int;
> +  using c = int;
> +  b d;
> +  void e() { g<c>(d); }
> +  template <typename... f> static void g(f...);
> +};
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-04 22:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-04 21:03 [PATCH] c++: Backport PR90505 fix to 9 Marek Polacek
2020-03-04 22:23 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).