]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Avoid -Wreturn-type warning if a template fn calls noreturn template fn [PR94742]
authorJakub Jelinek <jakub@redhat.com>
Fri, 24 Apr 2020 22:11:35 +0000 (00:11 +0200)
committerJakub Jelinek <jakub@redhat.com>
Wed, 16 Sep 2020 17:18:51 +0000 (19:18 +0200)
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.

(cherry picked from commit 4ff685a8705e8ee55fa86e75afb769ffb0975aea)

gcc/cp/semantics.c
gcc/testsuite/g++.dg/warn/Wreturn-type-12.C [new file with mode: 0644]

index 559e38dbc14e843635dd6ca9f41ad78b70769e6f..3c578fbfa60db2b2515e013e05f7d9abf9eb83d4 100644 (file)
@@ -2438,7 +2438,7 @@ finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
              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;
diff --git a/gcc/testsuite/g++.dg/warn/Wreturn-type-12.C b/gcc/testsuite/g++.dg/warn/Wreturn-type-12.C
new file mode 100644 (file)
index 0000000..b35d3fa
--- /dev/null
@@ -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>();
+}