From: Jakub Jelinek Date: Tue, 17 Dec 2019 21:40:14 +0000 (+0100) Subject: re PR c++/59655 (incorrect diagnostic on templatized function with lambda parameter) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=775670d792fb8ff314ed519ff295583ab31d90ef;p=gcc.git re PR c++/59655 (incorrect diagnostic on templatized function with lambda parameter) 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a64bb164664..6b5849e45b3 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2019-12-17 Jakub Jelinek + + 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 PR c++/91165 - verify_gimple ICE with cached constexpr. diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 46cc58265a6..ea83210fecb 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -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); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 6f658de28ed..fe6cfc2590b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0ba27eba78b..a3125166f97 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2019-12-17 Jakub Jelinek + 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 index 00000000000..7409b30fb4b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/diag3.C @@ -0,0 +1,20 @@ +// PR c++/59655 +// { dg-do compile { target c++11 } } + +template struct A { static constexpr bool value = false; }; + +struct B { + template + B (T t) + { + static_assert (A::value, "baz"); // { dg-error "static assertion failed" } + foo (t); + } + template void foo (T) {} // { dg-bogus "used but never defined" } +}; + +int +main () +{ + B t([](int) { }); +}