re PR c++/21117 (ICE after error about returning an incomplete type)
authorNathan Sidwell <nathan@codesourcery.com>
Wed, 12 Oct 2005 18:02:52 +0000 (18:02 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Wed, 12 Oct 2005 18:02:52 +0000 (18:02 +0000)
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
gcc/cp/decl.c
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/return1.C [new file with mode: 0644]

index 23eeade..a94a3fb 100644 (file)
@@ -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
index 91d76ba..b76c12d 100644 (file)
@@ -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));
index 7a9a561..d8210f1 100644 (file)
@@ -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.  */
index 6787a81..d5eac84 100644 (file)
@@ -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 (file)
index 0000000..2473b8d
--- /dev/null
@@ -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();
+}
+
+