This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for -Wreturn-type in templates
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 18 Dec 2002 01:25:59 -0500
- Subject: C++ PATCH for -Wreturn-type in templates
It's useful to know that you forgot to add a return statement in a
template, even if it is never instantiated.
Tested i686-pc-linux-gnu. Test in g++.dg/warn/noreturn-2.C.
Applied to trunk.
2002-12-17 Jason Merrill <jason@redhat.com>
* decl.c (finish_function): Also complain about no return in
templates.
* semantics.c (finish_return_stmt): Also call check_return_expr in
templates.
* typeck.c (check_return_expr): In a template, just remember that we
saw a return.
Index: gcc/cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.967
diff -c -p -r1.967 decl.c
*** gcc/cp/decl.c 17 Dec 2002 06:24:00 -0000 1.967
--- gcc/cp/decl.c 18 Dec 2002 04:04:45 -0000
*************** finish_function (flags)
*** 14540,14546 ****
/* Complain if there's just no return statement. */
if (warn_return_type
- && !processing_template_decl
&& TREE_CODE (TREE_TYPE (fntype)) != VOID_TYPE
&& !current_function_returns_value && !current_function_returns_null
/* Don't complain if we abort or throw. */
--- 14540,14545 ----
*************** finish_function (flags)
*** 14548,14554 ****
&& !DECL_NAME (DECL_RESULT (fndecl))
/* Normally, with -Wreturn-type, flow will complain. Unless we're an
inline function, as we might never be compiled separately. */
! && DECL_INLINE (fndecl))
warning ("no return statement in function returning non-void");
/* Clear out memory we no longer need. */
--- 14547,14553 ----
&& !DECL_NAME (DECL_RESULT (fndecl))
/* Normally, with -Wreturn-type, flow will complain. Unless we're an
inline function, as we might never be compiled separately. */
! && (DECL_INLINE (fndecl) || processing_template_decl))
warning ("no return statement in function returning non-void");
/* Clear out memory we no longer need. */
Index: gcc/cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.285
diff -c -p -r1.285 semantics.c
*** gcc/cp/semantics.c 17 Dec 2002 21:29:29 -0000 1.285
--- gcc/cp/semantics.c 18 Dec 2002 04:04:45 -0000
*************** finish_return_stmt (expr)
*** 400,407 ****
{
tree r;
! if (!processing_template_decl)
! expr = check_return_expr (expr);
if (!processing_template_decl)
{
if (DECL_DESTRUCTOR_P (current_function_decl))
--- 400,406 ----
{
tree r;
! expr = check_return_expr (expr);
if (!processing_template_decl)
{
if (DECL_DESTRUCTOR_P (current_function_decl))
Index: gcc/cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.437
diff -c -p -r1.437 typeck.c
*** gcc/cp/typeck.c 16 Dec 2002 18:22:20 -0000 1.437
--- gcc/cp/typeck.c 18 Dec 2002 04:04:46 -0000
*************** check_return_expr (retval)
*** 6172,6177 ****
--- 6172,6183 ----
return NULL_TREE;
}
+ if (processing_template_decl)
+ {
+ current_function_returns_value = 1;
+ return retval;
+ }
+
/* When no explicit return-value is given in a function with a named
return value, the named return value is used. */
result = DECL_RESULT (current_function_decl);