Hi!

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.

Fixed thusly, bootstrapped/regtested on powerpc64{,le}-linux, ok for trunk?

2020-04-24  Jakub Jelinek  <ja...@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.

--- gcc/cp/semantics.c.jj       2020-03-30 22:54:37.828795752 +0200
+++ gcc/cp/semantics.c  2020-04-24 14:30:36.001664888 +0200
@@ -2508,7 +2508,7 @@ finish_call_expr (tree fn, vec<tree, va_
              bool abnormal = true;
              for (lkp_iterator iter (fn); abnormal && iter; ++iter)
                {
-                 tree fndecl = *iter;
+                 tree fndecl = STRIP_TEMPLATE (*iter);
                  if (TREE_CODE (fndecl) != FUNCTION_DECL
                      || !TREE_THIS_VOLATILE (fndecl))
                    abnormal = false;
--- gcc/testsuite/g++.dg/warn/Wreturn-type-12.C.jj      2020-04-24 
14:34:24.700215365 +0200
+++ gcc/testsuite/g++.dg/warn/Wreturn-type-12.C 2020-04-24 14:34:15.858348723 
+0200
@@ -0,0 +1,23 @@
+// 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>();
+}

        Jakub

Reply via email to