public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: respect complain for -Wctad-maybe-unsupported [PR105143]
@ 2022-04-06 15:11 Patrick Palka
  2022-04-06 15:19 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2022-04-06 15:11 UTC (permalink / raw)
  To: gcc-patches

We were attempting to issue a -Wctad-maybe-unsupported warning even when
complain=tf_none, which led to a crash in the first testcase below and a
bogus error during SFINAE in the second testcase.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk/11?

	PR c++/105143

gcc/cp/ChangeLog:

	* pt.cc (do_class_deduction): Check complain before issuing a
	-Wctad-maybe-unsupported warning.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/nodiscard1.C: New test.
	* g++.dg/warn/Wctad-maybe-unsupported4.C: New test.
---
 gcc/cp/pt.cc                                        |  2 +-
 gcc/testsuite/g++.dg/cpp2a/nodiscard1.C             | 13 +++++++++++++
 .../g++.dg/warn/Wctad-maybe-unsupported4.C          | 12 ++++++++++++
 3 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/nodiscard1.C
 create mode 100644 gcc/testsuite/g++.dg/warn/Wctad-maybe-unsupported4.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 1f0231f70e6..1805fa68440 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -30075,7 +30075,7 @@ do_class_deduction (tree ptype, tree tmpl, tree init,
 
   /* If CTAD succeeded but the type doesn't have any explicit deduction
      guides, this deduction might not be what the user intended.  */
-  if (fndecl != error_mark_node && !any_dguides_p)
+  if ((complain & tf_warning) && fndecl != error_mark_node && !any_dguides_p)
     {
       if ((!DECL_IN_SYSTEM_HEADER (fndecl)
 	   || global_dc->dc_warn_system_headers)
diff --git a/gcc/testsuite/g++.dg/cpp2a/nodiscard1.C b/gcc/testsuite/g++.dg/cpp2a/nodiscard1.C
new file mode 100644
index 00000000000..c3c5094b619
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/nodiscard1.C
@@ -0,0 +1,13 @@
+// PR c++/105143
+// { dg-do compile { target c++20 } }
+// We used to crash here with "Error reporting routines re-entered".
+
+template<class...> struct A { };
+
+template<A V> using type = int;
+
+template<A V> [[nodiscard]] type<V> get();
+
+int main() {
+  get<{}>(); // { dg-warning "nodiscard" }
+}
diff --git a/gcc/testsuite/g++.dg/warn/Wctad-maybe-unsupported4.C b/gcc/testsuite/g++.dg/warn/Wctad-maybe-unsupported4.C
new file mode 100644
index 00000000000..0d0e2fb45eb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wctad-maybe-unsupported4.C
@@ -0,0 +1,12 @@
+// PR c++/105143
+// { dg-do compile { target c++17 } }
+// { dg-additional-options "-Werror=ctad-maybe-unsupported" }
+
+template<class...> struct A { };
+
+template<template<class...> class TT> auto f(...) -> decltype(TT()); // #1
+template<template<class...> class TT> void f(int); // #2
+
+int main() {
+  f<A>(0); // Calls #2 without issuing a -Wctad-maybe-unsupported diagnostic.
+}
-- 
2.36.0.rc0


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

* Re: [PATCH] c++: respect complain for -Wctad-maybe-unsupported [PR105143]
  2022-04-06 15:11 [PATCH] c++: respect complain for -Wctad-maybe-unsupported [PR105143] Patrick Palka
@ 2022-04-06 15:19 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2022-04-06 15:19 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

On 4/6/22 11:11, Patrick Palka wrote:
> We were attempting to issue a -Wctad-maybe-unsupported warning even when
> complain=tf_none, which led to a crash in the first testcase below and a
> bogus error during SFINAE in the second testcase.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk/11?

OK.

> 	PR c++/105143
> 
> gcc/cp/ChangeLog:
> 
> 	* pt.cc (do_class_deduction): Check complain before issuing a
> 	-Wctad-maybe-unsupported warning.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp2a/nodiscard1.C: New test.
> 	* g++.dg/warn/Wctad-maybe-unsupported4.C: New test.
> ---
>   gcc/cp/pt.cc                                        |  2 +-
>   gcc/testsuite/g++.dg/cpp2a/nodiscard1.C             | 13 +++++++++++++
>   .../g++.dg/warn/Wctad-maybe-unsupported4.C          | 12 ++++++++++++
>   3 files changed, 26 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/nodiscard1.C
>   create mode 100644 gcc/testsuite/g++.dg/warn/Wctad-maybe-unsupported4.C
> 
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 1f0231f70e6..1805fa68440 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -30075,7 +30075,7 @@ do_class_deduction (tree ptype, tree tmpl, tree init,
>   
>     /* If CTAD succeeded but the type doesn't have any explicit deduction
>        guides, this deduction might not be what the user intended.  */
> -  if (fndecl != error_mark_node && !any_dguides_p)
> +  if ((complain & tf_warning) && fndecl != error_mark_node && !any_dguides_p)
>       {
>         if ((!DECL_IN_SYSTEM_HEADER (fndecl)
>   	   || global_dc->dc_warn_system_headers)
> diff --git a/gcc/testsuite/g++.dg/cpp2a/nodiscard1.C b/gcc/testsuite/g++.dg/cpp2a/nodiscard1.C
> new file mode 100644
> index 00000000000..c3c5094b619
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/nodiscard1.C
> @@ -0,0 +1,13 @@
> +// PR c++/105143
> +// { dg-do compile { target c++20 } }
> +// We used to crash here with "Error reporting routines re-entered".
> +
> +template<class...> struct A { };
> +
> +template<A V> using type = int;
> +
> +template<A V> [[nodiscard]] type<V> get();
> +
> +int main() {
> +  get<{}>(); // { dg-warning "nodiscard" }
> +}
> diff --git a/gcc/testsuite/g++.dg/warn/Wctad-maybe-unsupported4.C b/gcc/testsuite/g++.dg/warn/Wctad-maybe-unsupported4.C
> new file mode 100644
> index 00000000000..0d0e2fb45eb
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/warn/Wctad-maybe-unsupported4.C
> @@ -0,0 +1,12 @@
> +// PR c++/105143
> +// { dg-do compile { target c++17 } }
> +// { dg-additional-options "-Werror=ctad-maybe-unsupported" }
> +
> +template<class...> struct A { };
> +
> +template<template<class...> class TT> auto f(...) -> decltype(TT()); // #1
> +template<template<class...> class TT> void f(int); // #2
> +
> +int main() {
> +  f<A>(0); // Calls #2 without issuing a -Wctad-maybe-unsupported diagnostic.
> +}


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

end of thread, other threads:[~2022-04-06 15:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-06 15:11 [PATCH] c++: respect complain for -Wctad-maybe-unsupported [PR105143] Patrick Palka
2022-04-06 15:19 ` 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).