public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-9797] c++: make -Wctad-maybe-unsupported respect complain [PR105143]
@ 2022-04-07 19:19 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2022-04-07 19:19 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:4e47b450b72f082de6fba7a060c3a751954e6c17

commit r11-9797-g4e47b450b72f082de6fba7a060c3a751954e6c17
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Apr 6 11:46:25 2022 -0400

    c++: make -Wctad-maybe-unsupported respect complain [PR105143]
    
    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 overload resolution in the second testcase.
    
            PR c++/105143
    
    gcc/cp/ChangeLog:
    
            * pt.c (do_class_deduction): Check complain before attempting
            to issue a -Wctad-maybe-unsupported warning.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp2a/nodiscard1.C: New test.
            * g++.dg/warn/Wctad-maybe-unsupported4.C: New test.
    
    (cherry picked from commit e58484a019c57b1085bbbcc1654f1944feddfe73)

Diff:
---
 gcc/cp/pt.c                                          |  2 +-
 gcc/testsuite/g++.dg/cpp2a/nodiscard1.C              | 13 +++++++++++++
 gcc/testsuite/g++.dg/warn/Wctad-maybe-unsupported4.C | 13 +++++++++++++
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index c208985e9fb..aa68dd477df 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -29567,7 +29567,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 (call != error_mark_node && !any_dguides_p)
+  if (call != error_mark_node && !any_dguides_p && (complain & tf_warning))
     {
       tree fndecl = cp_get_callee_fndecl_nofold (call);
       if (fndecl != NULL_TREE
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..92ed8214b1d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wctad-maybe-unsupported4.C
@@ -0,0 +1,13 @@
+// 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 for #1.
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-07 19:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-07 19:19 [gcc r11-9797] c++: make -Wctad-maybe-unsupported respect complain [PR105143] 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).