aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@codesourcery.com>2005-10-12 18:02:52 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2005-10-12 18:02:52 +0000
commit51b15ede491940fcc66789e704474a67387ae705 (patch)
tree28c8ceb85e19b95157c495f5cb3810b89e15b055 /gcc
parenta4d25453fa85f413a7b1e61d989a90a32b6f7d09 (diff)
downloadgcc-51b15ede491940fcc66789e704474a67387ae705.zip
gcc-51b15ede491940fcc66789e704474a67387ae705.tar.gz
gcc-51b15ede491940fcc66789e704474a67387ae705.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/decl.c23
-rw-r--r--gcc/cp/typeck.c5
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/other/return1.C15
5 files changed, 42 insertions, 14 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 23eeade..a94a3fb 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2005-10-12 Nathan Sidwell <nathan@codesourcery.com>
+
+ 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 <edelsohn@gnu.org>
PR c++/23730
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 91d76ba..b76c12d 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 7a9a561..d8210f1 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 6787a81..d5eac84 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2005-10-12 Nathan Sidwell <nathan@codesourcery.com>
+
+ PR c++/21117
+ * g++.dg/other/return1.C: New.
+
2005-10-12 Paolo Bonzini <bonzini@gnu.org>
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 0000000..2473b8d
--- /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 <nathan@codesourcery.com>
+
+// PR 21117:ICE after error
+// Origin: Andrew Pinski <pinskia@gcc.gnu.org>
+
+struct wxString;
+struct wxString* wxGetEmptyString();
+
+struct wxString GetHeader() // { dg-error "return type" "" }
+{
+ return *wxGetEmptyString();
+}
+
+