diff options
author | Jason Merrill <jason@redhat.com> | 2002-12-18 01:26:58 -0500 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2002-12-18 01:26:58 -0500 |
commit | efc7052de7e511d905b02d6a5b3ab0723c8d7184 (patch) | |
tree | 3727454db91755cc5c5682b1e2548bc248ce433d /gcc | |
parent | a3a0177e779d569c6e906cb7b94c22c327d6363b (diff) | |
download | gcc-efc7052de7e511d905b02d6a5b3ab0723c8d7184.zip gcc-efc7052de7e511d905b02d6a5b3ab0723c8d7184.tar.gz gcc-efc7052de7e511d905b02d6a5b3ab0723c8d7184.tar.bz2 |
decl.c (finish_function): Also complain about no return in templates.
* 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.
From-SVN: r60236
Diffstat (limited to 'gcc')
-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 1e50ff9..67b90ad 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 2d6b4a4..870a13d 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 e402a72..42a740d 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 1c78dd1..769702b 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 0000000..3b18e1d --- /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" } |