diff options
author | Jakub Jelinek <jakub@redhat.com> | 2019-12-17 22:40:14 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2019-12-17 22:40:14 +0100 |
commit | 775670d792fb8ff314ed519ff295583ab31d90ef (patch) | |
tree | 94943061d740b279a0ec3ea2703b678fad5b23f8 | |
parent | 7c32b0d5ccd3dcd0358f4fa2207713754b768649 (diff) | |
download | gcc-775670d792fb8ff314ed519ff295583ab31d90ef.zip gcc-775670d792fb8ff314ed519ff295583ab31d90ef.tar.gz gcc-775670d792fb8ff314ed519ff295583ab31d90ef.tar.bz2 |
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
-rw-r--r-- | gcc/cp/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/cp/decl2.c | 9 | ||||
-rw-r--r-- | gcc/cp/pt.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/diag3.C | 20 |
5 files changed, 45 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a64bb16..6b5849e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -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. diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 46cc582..ea83210 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 6f658de..fe6cfc2 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 0ba27eb..a312516 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 0000000..7409b30 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/diag3.C @@ -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) { }); +} |