public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Reject alias CTAD in C++17 [PR99008]
@ 2021-04-10 19:57 Patrick Palka
  2021-04-12 21:26 ` Jason Merrill
  0 siblings, 1 reply; 6+ messages in thread
From: Patrick Palka @ 2021-04-10 19:57 UTC (permalink / raw)
  To: gcc-patches

Here, in C++17 mode, we only pedwarn about the use of alias CTAD and
then later ICE from alias_ctad_tweaks when attempting to add a
constraint to one of the guides.  Since the construction of the guides
of an alias template effectively relies on concepts, we shouldn't be
permissive about alias CTAD in C++17 mode, so this patch turns the
pertinent pedwarn in do_class_deduction into an error.

In order to get a consistent diagnostic for B() vs the other forms in
the added testcase, I had to remove the special handling of CTAD with
empty initializer in build_functional_cast_1 so that we always pass
'complain' to do_auto_deduction.

Tested on x86_64-pc-linux-gnu, does this look OK for trunk?

gcc/cp/ChangeLog:

	PR c++/99008
	* pt.c (do_class_deduction): Reject alias CTAD in C++17 mode
	rather than issuing a pedwarn.
	* typeck2.c (build_functional_cast_1): Handle CTAD uniformly.

gcc/testsuite/ChangeLog:

	PR c++/99008
	* g++.dg/parse/template2.C: Adjust expected diagnostic.
	* g++.dg/template/error8.C: Likewise.
	* g++.dg/cpp1z/class-deduction84.C: New test.
---
 gcc/cp/pt.c                                    |  8 ++++----
 gcc/cp/typeck2.c                               | 17 +++--------------
 gcc/testsuite/g++.dg/cpp1z/class-deduction84.C |  9 +++++++++
 gcc/testsuite/g++.dg/parse/template2.C         |  2 +-
 gcc/testsuite/g++.dg/template/error8.C         |  2 +-
 5 files changed, 18 insertions(+), 20 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1z/class-deduction84.C

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index abd1ad4d1a6..40458102304 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -29290,10 +29290,10 @@ do_class_deduction (tree ptype, tree tmpl, tree init,
     }
   else if (cxx_dialect < cxx20 && DECL_ALIAS_TEMPLATE_P (tmpl))
     {
-      /* This doesn't affect conforming C++17 code, so just pedwarn.  */
-      if (complain & tf_warning_or_error)
-	pedwarn (input_location, 0, "alias template deduction only available "
-		 "with %<-std=c++20%> or %<-std=gnu++20%>");
+      if (complain & tf_error)
+	error ("alias template deduction only available "
+	       "with %<-std=c++20%> or %<-std=gnu++20%>");
+      return error_mark_node;
     }
 
   tree type = TREE_TYPE (tmpl);
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index a58d397ca3f..4e9632f6a7d 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -2197,24 +2197,13 @@ build_functional_cast_1 (location_t loc, tree exp, tree parms,
 	    error_at (loc, "invalid use of %qT", anode);
 	  return error_mark_node;
 	}
-      else if (!parms)
+      else
 	{
-	  /* Even if there are no parameters, we might be able to deduce from
-	     default template arguments.  Pass TF_NONE so that we don't
-	     generate redundant diagnostics.  */
-	  type = do_auto_deduction (type, parms, anode, tf_none,
+	  type = do_auto_deduction (type, parms, anode, complain,
 				    adc_variable_type);
 	  if (type == error_mark_node)
-	    {
-	      if (complain & tf_error)
-		error_at (loc, "cannot deduce template arguments "
-			  "for %qT from %<()%>", anode);
-	      return error_mark_node;
-	    }
+	    return error_mark_node;
 	}
-      else
-	type = do_auto_deduction (type, parms, anode, complain,
-				  adc_variable_type);
     }
 
   if (processing_template_decl)
diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction84.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction84.C
new file mode 100644
index 00000000000..29f25e50c9e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction84.C
@@ -0,0 +1,9 @@
+// PR c++/99008
+// { dg-do compile { target c++17 } }
+
+template <class> struct A { A(int = 0); };
+template <class = void> using B = A<int>;
+auto x = B{};  // { dg-error "alias template deduction only available with" "" { target c++17_only } }
+auto y = B();  // { dg-error "alias template deduction only available with" "" { target c++17_only } }
+auto z = B{1}; // { dg-error "alias template deduction only available with" "" { target c++17_only } }
+auto w = B(1); // { dg-error "alias template deduction only available with" "" { target c++17_only } }
diff --git a/gcc/testsuite/g++.dg/parse/template2.C b/gcc/testsuite/g++.dg/parse/template2.C
index 3cb27a85c00..3cafd9f1f01 100644
--- a/gcc/testsuite/g++.dg/parse/template2.C
+++ b/gcc/testsuite/g++.dg/parse/template2.C
@@ -3,6 +3,6 @@ namespace N {
 }
 
 int main() {
-  N::C(); // { dg-error "6:cannot deduce template arguments" "" { target c++17 } }
+  N::C(); // { dg-error "8:class template argument deduction failed|no match" "" { target c++17 } }
   // { dg-error "7:missing template arguments" "" { target c++14_down } .-1 }
 }
diff --git a/gcc/testsuite/g++.dg/template/error8.C b/gcc/testsuite/g++.dg/template/error8.C
index 6cae360aa16..de1534cc637 100644
--- a/gcc/testsuite/g++.dg/template/error8.C
+++ b/gcc/testsuite/g++.dg/template/error8.C
@@ -3,6 +3,6 @@
 template <typename T> struct S {};
 
 void f() {
-  throw S (); // { dg-error "9:cannot deduce template arguments" "" { target c++17 } }
+  throw S (); // { dg-error "12:class template argument deduction failed|no match" "" { target c++17 } }
   // { dg-error "11:missing template arguments" "" { target c++14_down } .-1 }
 }
-- 
2.31.1.272.g89b43f80a5


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

* Re: [PATCH] c++: Reject alias CTAD in C++17 [PR99008]
  2021-04-10 19:57 [PATCH] c++: Reject alias CTAD in C++17 [PR99008] Patrick Palka
@ 2021-04-12 21:26 ` Jason Merrill
  2021-04-12 22:24   ` Patrick Palka
  0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2021-04-12 21:26 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

On 4/10/21 3:57 PM, Patrick Palka wrote:
> Here, in C++17 mode, we only pedwarn about the use of alias CTAD and
> then later ICE from alias_ctad_tweaks when attempting to add a
> constraint to one of the guides.  Since the construction of the guides
> of an alias template effectively relies on concepts, we shouldn't be
> permissive about alias CTAD in C++17 mode, so this patch turns the
> pertinent pedwarn in do_class_deduction into an error.

Sounds good.

> In order to get a consistent diagnostic for B() vs the other forms in
> the added testcase, I had to remove the special handling of CTAD with
> empty initializer in build_functional_cast_1 so that we always pass
> 'complain' to do_auto_deduction.

Did you compare the resulting diagnostics when deduction fails other 
than for trying to do alias deduction in C++17 mode?

> Tested on x86_64-pc-linux-gnu, does this look OK for trunk?
> 
> gcc/cp/ChangeLog:
> 
> 	PR c++/99008
> 	* pt.c (do_class_deduction): Reject alias CTAD in C++17 mode
> 	rather than issuing a pedwarn.
> 	* typeck2.c (build_functional_cast_1): Handle CTAD uniformly.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR c++/99008
> 	* g++.dg/parse/template2.C: Adjust expected diagnostic.
> 	* g++.dg/template/error8.C: Likewise.
> 	* g++.dg/cpp1z/class-deduction84.C: New test.
> ---
>   gcc/cp/pt.c                                    |  8 ++++----
>   gcc/cp/typeck2.c                               | 17 +++--------------
>   gcc/testsuite/g++.dg/cpp1z/class-deduction84.C |  9 +++++++++
>   gcc/testsuite/g++.dg/parse/template2.C         |  2 +-
>   gcc/testsuite/g++.dg/template/error8.C         |  2 +-
>   5 files changed, 18 insertions(+), 20 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp1z/class-deduction84.C
> 
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index abd1ad4d1a6..40458102304 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -29290,10 +29290,10 @@ do_class_deduction (tree ptype, tree tmpl, tree init,
>       }
>     else if (cxx_dialect < cxx20 && DECL_ALIAS_TEMPLATE_P (tmpl))
>       {
> -      /* This doesn't affect conforming C++17 code, so just pedwarn.  */
> -      if (complain & tf_warning_or_error)
> -	pedwarn (input_location, 0, "alias template deduction only available "
> -		 "with %<-std=c++20%> or %<-std=gnu++20%>");
> +      if (complain & tf_error)
> +	error ("alias template deduction only available "
> +	       "with %<-std=c++20%> or %<-std=gnu++20%>");
> +      return error_mark_node;
>       }
>   
>     tree type = TREE_TYPE (tmpl);
> diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
> index a58d397ca3f..4e9632f6a7d 100644
> --- a/gcc/cp/typeck2.c
> +++ b/gcc/cp/typeck2.c
> @@ -2197,24 +2197,13 @@ build_functional_cast_1 (location_t loc, tree exp, tree parms,
>   	    error_at (loc, "invalid use of %qT", anode);
>   	  return error_mark_node;
>   	}
> -      else if (!parms)
> +      else
>   	{
> -	  /* Even if there are no parameters, we might be able to deduce from
> -	     default template arguments.  Pass TF_NONE so that we don't
> -	     generate redundant diagnostics.  */
> -	  type = do_auto_deduction (type, parms, anode, tf_none,
> +	  type = do_auto_deduction (type, parms, anode, complain,
>   				    adc_variable_type);
>   	  if (type == error_mark_node)
> -	    {
> -	      if (complain & tf_error)
> -		error_at (loc, "cannot deduce template arguments "
> -			  "for %qT from %<()%>", anode);
> -	      return error_mark_node;
> -	    }
> +	    return error_mark_node;
>   	}
> -      else
> -	type = do_auto_deduction (type, parms, anode, complain,
> -				  adc_variable_type);
>       }
>   
>     if (processing_template_decl)
> diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction84.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction84.C
> new file mode 100644
> index 00000000000..29f25e50c9e
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction84.C
> @@ -0,0 +1,9 @@
> +// PR c++/99008
> +// { dg-do compile { target c++17 } }
> +
> +template <class> struct A { A(int = 0); };
> +template <class = void> using B = A<int>;
> +auto x = B{};  // { dg-error "alias template deduction only available with" "" { target c++17_only } }
> +auto y = B();  // { dg-error "alias template deduction only available with" "" { target c++17_only } }
> +auto z = B{1}; // { dg-error "alias template deduction only available with" "" { target c++17_only } }
> +auto w = B(1); // { dg-error "alias template deduction only available with" "" { target c++17_only } }
> diff --git a/gcc/testsuite/g++.dg/parse/template2.C b/gcc/testsuite/g++.dg/parse/template2.C
> index 3cb27a85c00..3cafd9f1f01 100644
> --- a/gcc/testsuite/g++.dg/parse/template2.C
> +++ b/gcc/testsuite/g++.dg/parse/template2.C
> @@ -3,6 +3,6 @@ namespace N {
>   }
>   
>   int main() {
> -  N::C(); // { dg-error "6:cannot deduce template arguments" "" { target c++17 } }
> +  N::C(); // { dg-error "8:class template argument deduction failed|no match" "" { target c++17 } }
>     // { dg-error "7:missing template arguments" "" { target c++14_down } .-1 }
>   }
> diff --git a/gcc/testsuite/g++.dg/template/error8.C b/gcc/testsuite/g++.dg/template/error8.C
> index 6cae360aa16..de1534cc637 100644
> --- a/gcc/testsuite/g++.dg/template/error8.C
> +++ b/gcc/testsuite/g++.dg/template/error8.C
> @@ -3,6 +3,6 @@
>   template <typename T> struct S {};
>   
>   void f() {
> -  throw S (); // { dg-error "9:cannot deduce template arguments" "" { target c++17 } }
> +  throw S (); // { dg-error "12:class template argument deduction failed|no match" "" { target c++17 } }
>     // { dg-error "11:missing template arguments" "" { target c++14_down } .-1 }
>   }
> 


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

* Re: [PATCH] c++: Reject alias CTAD in C++17 [PR99008]
  2021-04-12 21:26 ` Jason Merrill
@ 2021-04-12 22:24   ` Patrick Palka
  2021-04-13 12:41     ` Jason Merrill
  0 siblings, 1 reply; 6+ messages in thread
From: Patrick Palka @ 2021-04-12 22:24 UTC (permalink / raw)
  To: Jason Merrill; +Cc: Patrick Palka, gcc-patches

On Mon, 12 Apr 2021, Jason Merrill wrote:

> On 4/10/21 3:57 PM, Patrick Palka wrote:
> > Here, in C++17 mode, we only pedwarn about the use of alias CTAD and
> > then later ICE from alias_ctad_tweaks when attempting to add a
> > constraint to one of the guides.  Since the construction of the guides
> > of an alias template effectively relies on concepts, we shouldn't be
> > permissive about alias CTAD in C++17 mode, so this patch turns the
> > pertinent pedwarn in do_class_deduction into an error.
> 
> Sounds good.
> 
> > In order to get a consistent diagnostic for B() vs the other forms in
> > the added testcase, I had to remove the special handling of CTAD with
> > empty initializer in build_functional_cast_1 so that we always pass
> > 'complain' to do_auto_deduction.
> 
> Did you compare the resulting diagnostics when deduction fails other than for
> trying to do alias deduction in C++17 mode?

For plain CTAD, e.g. for

  template <class T> struct A { };
  auto a = A();

we previously emitted

test.C:2:10: error: cannot deduce template arguments for ‘A<...auto...>’ from ‘()’
    2 | auto a = A();
      |          ^~~

and now we emit

test.C:2:12: error: class template argument deduction failed:
    2 | auto a = A();
      |            ^
test.C:2:12: error: no matching function for call to ‘A()’
test.C:1:27: note: candidate: ‘template<class T> A()-> A<T>’
    1 | template <class T> struct A { };
      |                           ^
test.C:1:27: note:   template argument deduction/substitution failed:
test.C:2:12: note:   couldn’t deduce template parameter ‘T’
    2 | auto a = A();
      |            ^
test.C:1:27: note: candidate: ‘template<class T> A(A<T>)-> A<T>’
    1 | template <class T> struct A { };
      |                           ^
test.C:1:27: note:   template argument deduction/substitution failed:
test.C:2:12: note:   candidate expects 1 argument, 0 provided
    2 | auto a = A();
      |            ^

which is consistent with what we already emit for failed CTAD of the
form A{}, A(args) and A{args}.

I think this change should have no diagnostic/functional impact in other
deduction situations because the code path is guarded by a
CLASS_PLACEHOLDER_TEMPLATE check (and we create template placeholders
only in C++17 mode).

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

* Re: [PATCH] c++: Reject alias CTAD in C++17 [PR99008]
  2021-04-12 22:24   ` Patrick Palka
@ 2021-04-13 12:41     ` Jason Merrill
  2021-04-13 19:19       ` Jason Merrill
  0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2021-04-13 12:41 UTC (permalink / raw)
  To: Patrick Palka; +Cc: gcc-patches

On 4/12/21 6:24 PM, Patrick Palka wrote:
> On Mon, 12 Apr 2021, Jason Merrill wrote:
> 
>> On 4/10/21 3:57 PM, Patrick Palka wrote:
>>> Here, in C++17 mode, we only pedwarn about the use of alias CTAD and
>>> then later ICE from alias_ctad_tweaks when attempting to add a
>>> constraint to one of the guides.  Since the construction of the guides
>>> of an alias template effectively relies on concepts, we shouldn't be
>>> permissive about alias CTAD in C++17 mode, so this patch turns the
>>> pertinent pedwarn in do_class_deduction into an error.
>>
>> Sounds good.
>>
>>> In order to get a consistent diagnostic for B() vs the other forms in
>>> the added testcase, I had to remove the special handling of CTAD with
>>> empty initializer in build_functional_cast_1 so that we always pass
>>> 'complain' to do_auto_deduction.
>>
>> Did you compare the resulting diagnostics when deduction fails other than for
>> trying to do alias deduction in C++17 mode?
> 
> For plain CTAD, e.g. for
> 
>    template <class T> struct A { };
>    auto a = A();
> 
> we previously emitted
> 
> test.C:2:10: error: cannot deduce template arguments for ‘A<...auto...>’ from ‘()’
>      2 | auto a = A();
>        |          ^~~
> 
> and now we emit
> 
> test.C:2:12: error: class template argument deduction failed:
>      2 | auto a = A();
>        |            ^
> test.C:2:12: error: no matching function for call to ‘A()’
> test.C:1:27: note: candidate: ‘template<class T> A()-> A<T>’
>      1 | template <class T> struct A { };
>        |                           ^
> test.C:1:27: note:   template argument deduction/substitution failed:
> test.C:2:12: note:   couldn’t deduce template parameter ‘T’
>      2 | auto a = A();
>        |            ^
> test.C:1:27: note: candidate: ‘template<class T> A(A<T>)-> A<T>’
>      1 | template <class T> struct A { };
>        |                           ^
> test.C:1:27: note:   template argument deduction/substitution failed:
> test.C:2:12: note:   candidate expects 1 argument, 0 provided
>      2 | auto a = A();
>        |            ^
> 
> which is consistent with what we already emit for failed CTAD of the
> form A{}, A(args) and A{args}.

Thanks, that's fine.  The patch is OK.

> I think this change should have no diagnostic/functional impact in other
> deduction situations because the code path is guarded by a
> CLASS_PLACEHOLDER_TEMPLATE check (and we create template placeholders
> only in C++17 mode).

Jason


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

* Re: [PATCH] c++: Reject alias CTAD in C++17 [PR99008]
  2021-04-13 12:41     ` Jason Merrill
@ 2021-04-13 19:19       ` Jason Merrill
  2021-04-13 19:42         ` Patrick Palka
  0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2021-04-13 19:19 UTC (permalink / raw)
  To: Patrick Palka; +Cc: gcc-patches

On 4/13/21 8:41 AM, Jason Merrill wrote:
> On 4/12/21 6:24 PM, Patrick Palka wrote:
>> On Mon, 12 Apr 2021, Jason Merrill wrote:
>>
>>> On 4/10/21 3:57 PM, Patrick Palka wrote:
>>>> Here, in C++17 mode, we only pedwarn about the use of alias CTAD and
>>>> then later ICE from alias_ctad_tweaks when attempting to add a
>>>> constraint to one of the guides.  Since the construction of the guides
>>>> of an alias template effectively relies on concepts, we shouldn't be
>>>> permissive about alias CTAD in C++17 mode, so this patch turns the
>>>> pertinent pedwarn in do_class_deduction into an error.
>>>
>>> Sounds good.
>>>
>>>> In order to get a consistent diagnostic for B() vs the other forms in
>>>> the added testcase, I had to remove the special handling of CTAD with
>>>> empty initializer in build_functional_cast_1 so that we always pass
>>>> 'complain' to do_auto_deduction.
>>>
>>> Did you compare the resulting diagnostics when deduction fails other 
>>> than for
>>> trying to do alias deduction in C++17 mode?
>>
>> For plain CTAD, e.g. for
>>
>>    template <class T> struct A { };
>>    auto a = A();
>>
>> we previously emitted
>>
>> test.C:2:10: error: cannot deduce template arguments for 
>> ‘A<...auto...>’ from ‘()’
>>      2 | auto a = A();
>>        |          ^~~
>>
>> and now we emit
>>
>> test.C:2:12: error: class template argument deduction failed:
>>      2 | auto a = A();
>>        |            ^
>> test.C:2:12: error: no matching function for call to ‘A()’
>> test.C:1:27: note: candidate: ‘template<class T> A()-> A<T>’
>>      1 | template <class T> struct A { };
>>        |                           ^
>> test.C:1:27: note:   template argument deduction/substitution failed:
>> test.C:2:12: note:   couldn’t deduce template parameter ‘T’
>>      2 | auto a = A();
>>        |            ^
>> test.C:1:27: note: candidate: ‘template<class T> A(A<T>)-> A<T>’
>>      1 | template <class T> struct A { };
>>        |                           ^
>> test.C:1:27: note:   template argument deduction/substitution failed:
>> test.C:2:12: note:   candidate expects 1 argument, 0 provided
>>      2 | auto a = A();
>>        |            ^
>>
>> which is consistent with what we already emit for failed CTAD of the
>> form A{}, A(args) and A{args}.
> 
> Thanks, that's fine.  The patch is OK.

Looks like you still need to adjust three testcases in g++.old-deja: 
g++.ns/crash3.C, g++.ns/template7.C, g++.pt/crash8.C.

Jason


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

* Re: [PATCH] c++: Reject alias CTAD in C++17 [PR99008]
  2021-04-13 19:19       ` Jason Merrill
@ 2021-04-13 19:42         ` Patrick Palka
  0 siblings, 0 replies; 6+ messages in thread
From: Patrick Palka @ 2021-04-13 19:42 UTC (permalink / raw)
  To: Jason Merrill; +Cc: Patrick Palka, gcc-patches

On Tue, 13 Apr 2021, Jason Merrill wrote:

> On 4/13/21 8:41 AM, Jason Merrill wrote:
> > On 4/12/21 6:24 PM, Patrick Palka wrote:
> > > On Mon, 12 Apr 2021, Jason Merrill wrote:
> > > 
> > > > On 4/10/21 3:57 PM, Patrick Palka wrote:
> > > > > Here, in C++17 mode, we only pedwarn about the use of alias CTAD and
> > > > > then later ICE from alias_ctad_tweaks when attempting to add a
> > > > > constraint to one of the guides.  Since the construction of the guides
> > > > > of an alias template effectively relies on concepts, we shouldn't be
> > > > > permissive about alias CTAD in C++17 mode, so this patch turns the
> > > > > pertinent pedwarn in do_class_deduction into an error.
> > > > 
> > > > Sounds good.
> > > > 
> > > > > In order to get a consistent diagnostic for B() vs the other forms in
> > > > > the added testcase, I had to remove the special handling of CTAD with
> > > > > empty initializer in build_functional_cast_1 so that we always pass
> > > > > 'complain' to do_auto_deduction.
> > > > 
> > > > Did you compare the resulting diagnostics when deduction fails other
> > > > than for
> > > > trying to do alias deduction in C++17 mode?
> > > 
> > > For plain CTAD, e.g. for
> > > 
> > >    template <class T> struct A { };
> > >    auto a = A();
> > > 
> > > we previously emitted
> > > 
> > > test.C:2:10: error: cannot deduce template arguments for ‘A<...auto...>’
> > > from ‘()’
> > >      2 | auto a = A();
> > >        |          ^~~
> > > 
> > > and now we emit
> > > 
> > > test.C:2:12: error: class template argument deduction failed:
> > >      2 | auto a = A();
> > >        |            ^
> > > test.C:2:12: error: no matching function for call to ‘A()’
> > > test.C:1:27: note: candidate: ‘template<class T> A()-> A<T>’
> > >      1 | template <class T> struct A { };
> > >        |                           ^
> > > test.C:1:27: note:   template argument deduction/substitution failed:
> > > test.C:2:12: note:   couldn’t deduce template parameter ‘T’
> > >      2 | auto a = A();
> > >        |            ^
> > > test.C:1:27: note: candidate: ‘template<class T> A(A<T>)-> A<T>’
> > >      1 | template <class T> struct A { };
> > >        |                           ^
> > > test.C:1:27: note:   template argument deduction/substitution failed:
> > > test.C:2:12: note:   candidate expects 1 argument, 0 provided
> > >      2 | auto a = A();
> > >        |            ^
> > > 
> > > which is consistent with what we already emit for failed CTAD of the
> > > form A{}, A(args) and A{args}.
> > 
> > Thanks, that's fine.  The patch is OK.
> 
> Looks like you still need to adjust three testcases in g++.old-deja:
> g++.ns/crash3.C, g++.ns/template7.C, g++.pt/crash8.C.

Drat, sorry about that.  Not sure how I missed these.  Fixed thusly
after testing on x86_64-pc-linux-gnu.

-- >8 --

Subject: [committed] c++: Adjust expected diagnostics for old-deja tests [PR99008]

I missed adjusting these tests in the recently committed r11-8155.

gcc/testsuite/ChangeLog:

	PR c++/99008
	* g++.old-deja/g++.ns/crash3.C: Adjust expected diagnostic.
	* g++.old-deja/g++.ns/template7.C: Likewise.
	* g++.old-deja/g++.pt/crash8.C: Likewise.
---
 gcc/testsuite/g++.old-deja/g++.ns/crash3.C    | 2 +-
 gcc/testsuite/g++.old-deja/g++.ns/template7.C | 2 +-
 gcc/testsuite/g++.old-deja/g++.pt/crash8.C    | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/testsuite/g++.old-deja/g++.ns/crash3.C b/gcc/testsuite/g++.old-deja/g++.ns/crash3.C
index 189298de6c5..b5e6323dba9 100644
--- a/gcc/testsuite/g++.old-deja/g++.ns/crash3.C
+++ b/gcc/testsuite/g++.old-deja/g++.ns/crash3.C
@@ -6,6 +6,6 @@ namespace N {
 
 void f()
 {
-  N::S(); // { dg-error "6:cannot deduce template arguments" "" { target c++17 } } invalid use of template
+  N::S(); // { dg-error "8:class template argument deduction failed|no match" "" { target c++17 } } invalid use of template
   // { dg-error "7:missing template arguments" "" { target c++14_down } .-1 }
 }
diff --git a/gcc/testsuite/g++.old-deja/g++.ns/template7.C b/gcc/testsuite/g++.old-deja/g++.ns/template7.C
index 71366b79d02..441a41249d1 100644
--- a/gcc/testsuite/g++.old-deja/g++.ns/template7.C
+++ b/gcc/testsuite/g++.old-deja/g++.ns/template7.C
@@ -8,6 +8,6 @@ namespace foo {
 }
 
 void baz() {
-  foo::bar(); // { dg-error "8:cannot deduce template arguments" "" { target c++17 } } template used as expression
+  foo::bar(); // { dg-error "12:class template argument deduction failed|no match" "" { target c++17 } } template used as expression
   // { dg-error "11:missing template arguments" "" { target c++14_down } .-1 }
 }
diff --git a/gcc/testsuite/g++.old-deja/g++.pt/crash8.C b/gcc/testsuite/g++.old-deja/g++.pt/crash8.C
index 7b4eff595bf..678a728f352 100644
--- a/gcc/testsuite/g++.old-deja/g++.pt/crash8.C
+++ b/gcc/testsuite/g++.old-deja/g++.pt/crash8.C
@@ -21,11 +21,11 @@ void doit(T x) {
   q2 = TestClass2<T>();
 
   TestClass1<T> p1;
-  p1 = TestClass1(); // { dg-error "8:cannot deduce template arguments" "" { target c++17 } } template used as expression
+  p1 = TestClass1(); // { dg-error "19:class template argument deduction failed|no match" "" { target c++17 } } template used as expression
   // { dg-error "18:missing template arguments" "" { target c++14_down } .-1 }
 
   TestClass2<T> p2;
-  p2 = TestClass2(); // { dg-error "8:cannot deduce template arguments" "" { target c++17 } } template used as expression
+  p2 = TestClass2(); // { dg-error "19:class template argument deduction failed|no match" "" { target c++17 } } template used as expression
   // { dg-error "18:missing template arguments" "" { target c++14_down } .-1 }
 }
 
-- 
2.31.1.272.g89b43f80a5

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

end of thread, other threads:[~2021-04-13 19:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-10 19:57 [PATCH] c++: Reject alias CTAD in C++17 [PR99008] Patrick Palka
2021-04-12 21:26 ` Jason Merrill
2021-04-12 22:24   ` Patrick Palka
2021-04-13 12:41     ` Jason Merrill
2021-04-13 19:19       ` Jason Merrill
2021-04-13 19:42         ` Patrick Palka

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).