re PR c++/59655 (incorrect diagnostic on templatized function with lambda parameter)
authorJakub Jelinek <jakub@redhat.com>
Tue, 17 Dec 2019 21:40:14 +0000 (22:40 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 17 Dec 2019 21:40:14 +0000 (22:40 +0100)
PR c++/59655
* pt.c (push_tinst_level_loc): If limit_bad_template_recursion,
set TREE_NO_WARNING on tldcl.
* decl2.c (no_linkage_error): Treat templates with TREE_NO_WARNING
as defined during error recovery.

* g++.dg/cpp0x/diag3.C: New test.

From-SVN: r279470

gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/diag3.C [new file with mode: 0644]

index a64bb1646644a961e4337a7126730f766f360ebc..6b5849e45b3dd8af732b19b2ea95897e93bd5d09 100644 (file)
@@ -1,3 +1,11 @@
+2019-12-17  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/59655
+       * pt.c (push_tinst_level_loc): If limit_bad_template_recursion,
+       set TREE_NO_WARNING on tldcl.
+       * decl2.c (no_linkage_error): Treat templates with TREE_NO_WARNING
+       as defined during error recovery.
+
 2019-12-13  Jason Merrill  <jason@redhat.com>
 
        PR c++/91165 - verify_gimple ICE with cached constexpr.
index 46cc58265a64fbab9133bf502869d015c07f7ab8..ea83210fecb82fdaa8b75f3a98fd67b1caf7dc12 100644 (file)
@@ -4414,7 +4414,14 @@ decl_maybe_constant_var_p (tree decl)
 void
 no_linkage_error (tree decl)
 {
-  if (cxx_dialect >= cxx11 && decl_defined_p (decl))
+  if (cxx_dialect >= cxx11
+      && (decl_defined_p (decl)
+         /* Treat templates which limit_bad_template_recursion decided
+            not to instantiate as if they were defined.  */
+         || (errorcount + sorrycount > 0
+             && DECL_LANG_SPECIFIC (decl)
+             && DECL_TEMPLATE_INFO (decl)
+             && TREE_NO_WARNING (decl))))
     /* In C++11 it's ok if the decl is defined.  */
     return;
   tree t = no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false);
index 6f658de28ed1cc6363a10be8678c4c6bbd28d130..fe6cfc2590b7c482111730ea565ef96ae1d1a78a 100644 (file)
@@ -10640,7 +10640,12 @@ push_tinst_level_loc (tree tldcl, tree targs, location_t loc)
      anything else.  Do allow deduction substitution and decls usable in
      constant expressions.  */
   if (!targs && limit_bad_template_recursion (tldcl))
-    return false;
+    {
+      /* Avoid no_linkage_errors and unused function warnings for this
+        decl.  */
+      TREE_NO_WARNING (tldcl) = 1;
+      return false;
+    }
 
   /* When not -quiet, dump template instantiations other than functions, since
      announce_function will take care of those.  */
index 0ba27eba78b6c8247267561fe70c711361317183..a3125166f97df5e18b2583f5136caab7cabadf54 100644 (file)
@@ -1,5 +1,8 @@
 2019-12-17  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/59655
+       * g++.dg/cpp0x/diag3.C: New test.
+
        PR target/92841
        * gcc.target/i386/pr92841.c: New test.
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/diag3.C b/gcc/testsuite/g++.dg/cpp0x/diag3.C
new file mode 100644 (file)
index 0000000..7409b30
--- /dev/null
@@ -0,0 +1,20 @@
+// PR c++/59655
+// { dg-do compile { target c++11 } }
+
+template<typename T> struct A { static constexpr bool value = false; };
+
+struct B {
+  template<typename T>
+  B (T t)
+  {
+    static_assert (A<T>::value, "baz");                // { dg-error "static assertion failed" }
+    foo (t);
+  }
+  template<typename T> void foo (T) {}         // { dg-bogus "used but never defined" }
+};
+
+int
+main ()
+{
+  B t([](int) { });
+}