Commit 4ff685a8 by Jakub Jelinek

c++: Avoid -Wreturn-type warning if a template fn calls noreturn template fn [PR94742]

finish_call_expr already has code to set current_function_returns_abnormally
if a template calls a noreturn function, but on the following testcase it
doesn't call a FUNCTION_DECL, but TEMPLATE_DECL instead, in which case
we didn't check noreturn at all and just assumed it could return.

2020-04-25  Jakub Jelinek  <jakub@redhat.com>

	PR c++/94742
	* semantics.c (finish_call_expr): When looking if all overloads
	are noreturn, use STRIP_TEMPLATE to look through TEMPLATE_DECLs.

	* g++.dg/warn/Wreturn-type-12.C: New test.
parent cf39dccf
2020-04-25 Jakub Jelinek <jakub@redhat.com>
PR c++/94742
* semantics.c (finish_call_expr): When looking if all overloads
are noreturn, use STRIP_TEMPLATE to look through TEMPLATE_DECLs.
2020-04-24 Martin Liska <mliska@suse.cz> 2020-04-24 Martin Liska <mliska@suse.cz>
* coroutines.cc: Fix compilation error for release checking * coroutines.cc: Fix compilation error for release checking
......
...@@ -2508,7 +2508,7 @@ finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual, ...@@ -2508,7 +2508,7 @@ finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
bool abnormal = true; bool abnormal = true;
for (lkp_iterator iter (fn); abnormal && iter; ++iter) for (lkp_iterator iter (fn); abnormal && iter; ++iter)
{ {
tree fndecl = *iter; tree fndecl = STRIP_TEMPLATE (*iter);
if (TREE_CODE (fndecl) != FUNCTION_DECL if (TREE_CODE (fndecl) != FUNCTION_DECL
|| !TREE_THIS_VOLATILE (fndecl)) || !TREE_THIS_VOLATILE (fndecl))
abnormal = false; abnormal = false;
......
2020-04-25 Jakub Jelinek <jakub@redhat.com> 2020-04-25 Jakub Jelinek <jakub@redhat.com>
PR c++/94742
* g++.dg/warn/Wreturn-type-12.C: New test.
PR tree-optimization/94734 PR tree-optimization/94734
PR tree-optimization/89430 PR tree-optimization/89430
* gcc.dg/tree-ssa/pr89430-1.c: Add xfail. * gcc.dg/tree-ssa/pr89430-1.c: Add xfail.
......
// PR c++/94742
// { dg-do compile { target c++11 } }
// { dg-options "-Wreturn-type" }
template <class T>
[[noreturn]] void
foo (T const &t, char const *)
{
throw T (t);
}
template <class U>
int
bar ()
{
foo (42, __FUNCTION__);
} // { dg-bogus "no return statement in function returning non-void" }
int
main ()
{
bar<long>();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment