]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: make -Wctad-maybe-unsupported respect complain [PR105143]
authorPatrick Palka <ppalka@redhat.com>
Wed, 6 Apr 2022 15:46:25 +0000 (11:46 -0400)
committerPatrick Palka <ppalka@redhat.com>
Thu, 7 Apr 2022 19:18:57 +0000 (15:18 -0400)
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)

gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp2a/nodiscard1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wctad-maybe-unsupported4.C [new file with mode: 0644]

index c208985e9fb9b5dbfa53225d31f30287c1a5891d..aa68dd477dfa818def110a44be1f6f38b9409190 100644 (file)
@@ -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 (file)
index 0000000..c3c5094
--- /dev/null
@@ -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 (file)
index 0000000..92ed821
--- /dev/null
@@ -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.
+}