public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r9-8885] c++: Avoid -Wreturn-type warning if a template fn calls noreturn template fn [PR94742]
@ 2020-09-16 19:20 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-09-16 19:20 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:e9dbd80b5e62a126ccb40970f0fb233f7e0ac3a6
commit r9-8885-ge9dbd80b5e62a126ccb40970f0fb233f7e0ac3a6
Author: Jakub Jelinek <jakub@redhat.com>
Date: Sat Apr 25 00:11:35 2020 +0200
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.
(cherry picked from commit 4ff685a8705e8ee55fa86e75afb769ffb0975aea)
Diff:
---
gcc/cp/semantics.c | 2 +-
gcc/testsuite/g++.dg/warn/Wreturn-type-12.C | 23 +++++++++++++++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 559e38dbc14..3c578fbfa60 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -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
index 00000000000..b35d3faafb0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wreturn-type-12.C
@@ -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>();
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-09-16 19:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-16 19:20 [gcc r9-8885] c++: Avoid -Wreturn-type warning if a template fn calls noreturn template fn [PR94742] Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).