This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] Don't warn about missing return statement if noreturn function is called in template (PR c++/30988)


Hi!

Even if a function is called with type dependent args, we might know
that it is a noreturn function which normally surpresses warning about
missing return stmt.  Though IMHO it is better to issue a false positive
warning than not warn about missing return.

Regtested on x86_64-linux, ok for trunk?

2007-11-17  Jakub Jelinek  <jakub@redhat.com>

	PR c++/30988
	semantics.c (finish_call_expr): Set current_function_returns_abnormally
	if fn is noreturn FUNCTION_DECL or OVERLOAD with all noreturn
	functions.

	* g++.dg/warn/noreturn-4.C: New test.
	* g++.dg/warn/noreturn-5.C: New test.
	* g++.dg/warn/noreturn-6.C: New test.
	* g++.dg/warn/noreturn-7.C: New test.

--- gcc/cp/semantics.c.jj	2007-11-11 23:00:06.000000000 +0100
+++ gcc/cp/semantics.c	2007-11-17 14:05:39.000000000 +0100
@@ -1846,6 +1846,25 @@ finish_call_expr (tree fn, tree args, bo
 	{
 	  result = build_nt_call_list (fn, args);
 	  KOENIG_LOOKUP_P (result) = koenig_p;
+	  if (cfun)
+	    {
+	      if (TREE_CODE (fn) == FUNCTION_DECL
+		  && TREE_THIS_VOLATILE (fn))
+		current_function_returns_abnormally = 1;
+	      else if (TREE_CODE (fn) == OVERLOAD)
+		{
+		  bool all_noreturn = true;
+		  while (fn)
+		    {
+		      if (TREE_CODE (OVL_CURRENT (fn)) == FUNCTION_DECL
+			  && !TREE_THIS_VOLATILE (OVL_CURRENT (fn)))
+			all_noreturn = false;
+		      fn = OVL_NEXT (fn);
+		    }
+		  if (all_noreturn)
+		    current_function_returns_abnormally = 1;
+		}
+	    }
 	  return result;
 	}
       if (!BASELINK_P (fn)
--- gcc/testsuite/g++.dg/warn/noreturn-4.C.jj	2007-11-17 14:36:36.000000000 +0100
+++ gcc/testsuite/g++.dg/warn/noreturn-4.C	2007-11-17 14:09:48.000000000 +0100
@@ -0,0 +1,13 @@
+// PR c++/30988
+// { dg-do compile }
+// { dg-options "-O2 -Wall" }
+
+void f (const char *) __attribute__ ((noreturn));
+
+template <typename T> struct A
+{
+  int g ()
+  {
+    f (__FUNCTION__);
+  }
+};
--- gcc/testsuite/g++.dg/warn/noreturn-5.C.jj	2007-11-17 14:36:36.000000000 +0100
+++ gcc/testsuite/g++.dg/warn/noreturn-5.C	2007-11-17 14:09:53.000000000 +0100
@@ -0,0 +1,15 @@
+// PR c++/30988
+// { dg-do compile }
+// { dg-options "-O2 -Wall" }
+
+void f (const char *) __attribute__ ((noreturn));
+void f (int) __attribute__ ((noreturn));
+void f (double) __attribute__ ((noreturn));
+
+template <typename T> struct A
+{
+  int g ()
+  {
+    f ((T) 0);
+  }
+};
--- gcc/testsuite/g++.dg/warn/noreturn-6.C.jj	2007-11-17 14:36:36.000000000 +0100
+++ gcc/testsuite/g++.dg/warn/noreturn-6.C	2007-11-17 14:09:59.000000000 +0100
@@ -0,0 +1,13 @@
+// PR c++/30988
+// { dg-do compile }
+// { dg-options "-O2 -Wall" }
+
+void f (const char *);
+
+template <typename T> struct A
+{
+  int g ()
+  {
+    f (__FUNCTION__);
+  }	// { dg-warning "no return statement in function returning non-void" }
+};
--- gcc/testsuite/g++.dg/warn/noreturn-7.C.jj	2007-11-17 14:36:36.000000000 +0100
+++ gcc/testsuite/g++.dg/warn/noreturn-7.C	2007-11-17 14:10:18.000000000 +0100
@@ -0,0 +1,15 @@
+// PR c++/30988
+// { dg-do compile }
+// { dg-options "-O2 -Wall" }
+
+void f (const char *) __attribute__ ((noreturn));
+void f (int);
+void f (double) __attribute__ ((noreturn));
+
+template <typename T> struct A
+{
+  int g ()
+  {
+    f ((T) 0);
+  }	// { dg-warning "no return statement in function returning non-void" }
+};

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]