From 51b15ede491940fcc66789e704474a67387ae705 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 12 Oct 2005 18:02:52 +0000 Subject: [PATCH] re PR c++/21117 (ICE after error about returning an incomplete type) cp: PR c++/21117 * decl.c (check_function_type): Correctly overwrite incomplete return type with void type. * typeck.c (check_return_expr): If the function's return type is void, don't try and convert a return expr. testsuite: PR c++/21117 * g++.dg/other/return1.C: New. From-SVN: r105310 --- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/decl.c | 23 +++++++++-------------- gcc/cp/typeck.c | 5 +++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/other/return1.C | 15 +++++++++++++++ 5 files changed, 42 insertions(+), 14 deletions(-) create mode 100644 gcc/testsuite/g++.dg/other/return1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 23eeadec61c..a94a3fb674b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2005-10-12 Nathan Sidwell + + PR c++/21117 + * decl.c (check_function_type): Correctly overwrite incomplete + return type with void type. + * typeck.c (check_return_expr): If the function's return type is + void, don't try and convert a return expr. + 2005-10-12 David Edelsohn PR c++/23730 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 91d76ba6216..b76c12dac5e 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -10012,25 +10012,20 @@ check_function_type (tree decl, tree current_function_parms) return; if (!COMPLETE_OR_VOID_TYPE_P (return_type)) { - error ("return type %q#T is incomplete", TREE_TYPE (fntype)); + tree args = TYPE_ARG_TYPES (fntype); + + error ("return type %q#T is incomplete", return_type); - /* Make it return void instead, but don't change the - type of the DECL_RESULT, in case we have a named return value. */ + /* Make it return void instead. */ if (TREE_CODE (fntype) == METHOD_TYPE) - { - tree ctype = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fntype))); - TREE_TYPE (decl) - = build_method_type_directly (ctype, - void_type_node, - FUNCTION_ARG_CHAIN (decl)); - } + fntype = build_method_type_directly (TREE_TYPE (TREE_VALUE (args)), + void_type_node, + TREE_CHAIN (args)); else - TREE_TYPE (decl) - = build_function_type (void_type_node, - TYPE_ARG_TYPES (TREE_TYPE (decl))); + fntype = build_function_type (void_type_node, args); TREE_TYPE (decl) = build_exception_variant (fntype, - TYPE_RAISES_EXCEPTIONS (fntype)); + TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl))); } else abstract_virtuals_error (decl, TREE_TYPE (fntype)); diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 7a9a561896b..d8210f1394b 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -6326,6 +6326,11 @@ check_return_expr (tree retval, bool *no_warning) /* The type the function is declared to return. */ tree functype = TREE_TYPE (TREE_TYPE (current_function_decl)); + /* The functype's return type will have been set to void, if it + was an incomplete type. Just treat this as 'return;' */ + if (VOID_TYPE_P (functype)) + return error_mark_node; + /* First convert the value to the function's return type, then to the type of return value's location to handle the case that functype is smaller than the valtype. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6787a81847c..d5eac84518c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-10-12 Nathan Sidwell + + PR c++/21117 + * g++.dg/other/return1.C: New. + 2005-10-12 Paolo Bonzini PR c++/24052 diff --git a/gcc/testsuite/g++.dg/other/return1.C b/gcc/testsuite/g++.dg/other/return1.C new file mode 100644 index 00000000000..2473b8deb4b --- /dev/null +++ b/gcc/testsuite/g++.dg/other/return1.C @@ -0,0 +1,15 @@ +// Copyright (C) 2005 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 12 Oct 2005 + +// PR 21117:ICE after error +// Origin: Andrew Pinski + +struct wxString; +struct wxString* wxGetEmptyString(); + +struct wxString GetHeader() // { dg-error "return type" "" } +{ + return *wxGetEmptyString(); +} + +