User account creation filtered due to spam.

Bug 18545 - [3.4 regression] ICE when returning undefined type
Summary: [3.4 regression] ICE when returning undefined type
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 minor
Target Milestone: 3.4.5
Assignee: Volker Reichelt
Keywords: error-recovery, ice-on-invalid-code, monitored, patch
Depends on:
Reported: 2004-11-18 16:02 UTC by Volker Reichelt
Modified: 2005-09-01 15:07 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2005-02-26 18:42:07


Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2004-11-18 16:02:54 UTC
The following invalid code snippet crashes the C++ frontend:

struct A;

A foo()
    A a;
    return a;
=================================================== In function 'A foo()': error: return type 'struct A' is incomplete error: aggregate 'A a' has incomplete type and cannot be defined internal compiler error: tree check: expected class 'type', have
'exceptional' (error_mark) in check_return_expr, at cp/typeck.c:6296
Please submit a full bug report, [etc.]

The bug is present since gcc 3.4.0.
Looks like it was introduced with the new parser:
: Search converges between 2002-12-14-trunk (#159) and 2002-12-29-trunk (#160).
Comment 1 Andrew Pinski 2004-11-18 16:06:01 UTC
Comment 2 Volker Reichelt 2004-11-25 02:42:11 UTC
Mark, it looks like the following patch fixes the problem.

Index: typeck.c
RCS file: /home/reichelt/GCC/CVS/gcc-cvs/gcc/gcc/cp/typeck.c,v
retrieving revision 1.597
diff -u -p -r1.597 typeck.c
--- typeck.c    22 Nov 2004 12:15:36 -0000      1.597
+++ typeck.c    25 Nov 2004 01:41:11 -0000
@@ -6287,6 +6287,7 @@ check_return_expr (tree retval)
   if (fn_returns_value_p && flag_elide_constructors)
       if (retval != NULL_TREE
+         && TREE_TYPE (retval) != error_mark_node
          && (current_function_return_value == NULL_TREE
              || current_function_return_value == retval)
          && TREE_CODE (retval) == VAR_DECL
Comment 3 Mark Mitchell 2004-11-25 02:45:07 UTC
Subject: Re:  [3.4/4.0 regression] ICE when returning undefined

reichelt at gcc dot gnu dot org wrote:
> ------- Additional Comments From reichelt at gcc dot gnu dot org  2004-11-25 02:42 -------
> Mark, it looks like the following patch fixes the problem.

Thanks; I've already got a slightly cleaner version.

Comment 4 CVS Commits 2004-11-25 17:12:12 UTC
Subject: Bug 18545

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	2004-11-25 17:11:37

Modified files:
	gcc            : ChangeLog c-common.c c-common.h c-typeck.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/g++.dg/expr: unary2.C 
	gcc/testsuite/g++.dg/ext: lvaddr.C 
	gcc/testsuite/g++.dg/opt: pr7503-3.C 
	gcc/testsuite/g++.old-deja/g++.other: friend7.C 
	gcc/cp         : ChangeLog class.c cp-tree.h decl.c 
	                 name-lookup.c pt.c tree.c typeck.c 
Added files:
	gcc/testsuite/g++.dg/template: crash28.C 
	gcc/testsuite/g++.dg/expr: return1.C 
	gcc/testsuite/g++.dg/parse: qualified3.C 

Log message:
	PR c++/18001
	* c-common.h (lvalue_use): Move here from c-ctypeck.c.
	(lvalue_or_else): Declare.
	* c-common.c (lvalue_or_else): Move here from c-typeck.c.
	* c-typeck.c (lvalue_use): Remove.
	(lvalue_or_else): Remove.
	PR c++/18556
	* toplev.c (check_global_declarations): Set DECL_IGNORED_P on
	unemitted variables with static storage duration.
	PR c++/18445
	* class.c (instantiate_type): Treat NON_DEPENDENT_EXPRs with
	unknown_type as non matching.  Tidy up.
	* pt.c (build_non_dependent_expr): Do not build a
	PR c++/18001
	* cp-tree.h (lvalue_or_else): Remove declaration.
	* tree.c (lvalue_or_else): Remove.
	* typeck.c (build_unary_op): Adjust call to lvalue_or_else.
	(build_modify_expr): Likewise.
	PR c++/18625
	* decl.c (duplicate_decls): Return error_mark_node on error, as
	PR c++/18466
	* decl.c (grokvardecl): Keep track of whether or not a there was
	explicit qualification.
	* name-lookup.c (set_decl_namespace): Complain about explicit
	qualification of a name within its own namespace.
	PR c++/18545
	* typeck.c (check_return_expr): Robustify.
	PR c++/18445
	* g++.dg/template/crash28.C: Likewise.
	PR c++/18001
	* g++.dg/expr/unary2.C: Adjust lvalue messages.
	* g++.dg/ext/lvaddr.C: Likewise.
	* g++.dg/opt/pr7503-3.C: Likewise.
	PR c++/18466
	* g++.dg/parse/qualified3.C: New test.
	* g++.old-deja/g++.other/friend7.C: Remove bogus qualification.
	PR c++/18545
	* g++.dg/expr/return1.C: New test.


Comment 5 Mark Mitchell 2004-11-25 17:42:58 UTC
Fixed in 4.0.
Comment 6 Volker Reichelt 2005-09-01 14:57:10 UTC
Taking care of the backport to the 3.4 branch.
Comment 8 Volker Reichelt 2005-09-01 15:07:42 UTC
Fixed also on the 3.4 branch.