public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Ian Lance Taylor <ian@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/gccgo] c++: Avoid -Wreturn-type warning if a template fn calls noreturn template fn [PR94742]
Date: Sun, 12 Jul 2020 17:32:40 +0000 (GMT)	[thread overview]
Message-ID: <20200712173240.189273851C20@sourceware.org> (raw)

https://gcc.gnu.org/g:4ff685a8705e8ee55fa86e75afb769ffb0975aea

commit 4ff685a8705e8ee55fa86e75afb769ffb0975aea
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.

Diff:
---
 gcc/cp/ChangeLog                            |  6 ++++++
 gcc/cp/semantics.c                          |  2 +-
 gcc/testsuite/ChangeLog                     |  3 +++
 gcc/testsuite/g++.dg/warn/Wreturn-type-12.C | 23 +++++++++++++++++++++++
 4 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 4d3049e67f3..5b9ff5a694c 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+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>
 
 	* coroutines.cc: Fix compilation error for release checking
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index c7a6064e9f3..64a7b76d437 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2508,7 +2508,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/ChangeLog b/gcc/testsuite/ChangeLog
index fa583670baf..b9be66865cd 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,8 @@
 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/89430
 	* gcc.dg/tree-ssa/pr89430-1.c: Add xfail.
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>();
+}


                 reply	other threads:[~2020-07-12 17:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200712173240.189273851C20@sourceware.org \
    --to=ian@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).