diff options
| author | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-12-18 06:26:58 +0000 |
|---|---|---|
| committer | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-12-18 06:26:58 +0000 |
| commit | 261c3c2001e3e339577d4fc1439c9984cfc149ec (patch) | |
| tree | 3727454db91755cc5c5682b1e2548bc248ce433d | |
| parent | fb8213580fb900660f3c2bc7c45c8df26c574942 (diff) | |
| download | ppe42-gcc-261c3c2001e3e339577d4fc1439c9984cfc149ec.tar.gz ppe42-gcc-261c3c2001e3e339577d4fc1439c9984cfc149ec.zip | |
* 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@60236 138bc75d-0d04-0410-961f-82ee72b054a4
| -rw-r--r-- | gcc/cp/ChangeLog | 9 | ||||
| -rw-r--r-- | gcc/cp/decl.c | 3 | ||||
| -rw-r--r-- | gcc/cp/semantics.c | 3 | ||||
| -rw-r--r-- | gcc/cp/typeck.c | 6 | ||||
| -rw-r--r-- | gcc/testsuite/g++.dg/warn/noreturn-2.C | 4 |
5 files changed, 21 insertions, 4 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1e50ff96905..67b90addcaa 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +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. + 2002-12-16 Jason Merrill <jason@redhat.com> * semantics.c (simplify_aggr_init_exprs_r): Don't change the type diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 2d6b4a4a28e..870a13dd283 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -14540,7 +14540,6 @@ finish_function (flags) /* 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. */ @@ -14548,7 +14547,7 @@ finish_function (flags) && !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)) + && (DECL_INLINE (fndecl) || processing_template_decl)) warning ("no return statement in function returning non-void"); /* Clear out memory we no longer need. */ diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index e402a72f894..42a740dd71f 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -400,8 +400,7 @@ finish_return_stmt (expr) { tree r; - if (!processing_template_decl) - expr = check_return_expr (expr); + expr = check_return_expr (expr); if (!processing_template_decl) { if (DECL_DESTRUCTOR_P (current_function_decl)) diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 1c78dd1d057..769702b8a1d 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -6172,6 +6172,12 @@ check_return_expr (retval) 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); diff --git a/gcc/testsuite/g++.dg/warn/noreturn-2.C b/gcc/testsuite/g++.dg/warn/noreturn-2.C new file mode 100644 index 00000000000..3b18e1dbcdf --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/noreturn-2.C @@ -0,0 +1,4 @@ +// { dg-options "-Wall" } + +template <class T> +int f (T t) { } // { dg-warning "no return" } |

