Bug 18177 - [4.0 regression] ICE with const_cast for undeclared variable
Summary: [4.0 regression] ICE with const_cast for undeclared variable
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Mark Mitchell
URL:
Keywords: error-recovery, ice-on-invalid-code, monitored
Depends on:
Blocks:
 
Reported: 2004-10-27 13:54 UTC by Volker Reichelt
Modified: 2004-11-03 02:56 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-10-27 13:57:53


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2004-10-27 13:54:15 UTC
The following invalid code snippet causes an ICE when compiled with mainline:

=============================
void foo()
{
    X;
    const_cast<int&>(X);
}
=============================

bug.cc: In function `void foo()':
bug.cc:3: error: 'X' was not declared in this scope
bug.cc:4: internal compiler error: tree check: expected class 'type', have
'exceptional' (error_mark) in build_pointer_type_for_mode, at tree.c:4118
Please submit a full bug report, [etc.]

The regression appeared in March 2004:
: Search converges between 2004-03-01-trunk (#446) and 2004-04-01-trunk (#447).
Comment 1 Andrew Pinski 2004-10-27 13:57:53 UTC
Confirmed.
Comment 2 Volker Reichelt 2004-10-27 14:29:16 UTC
Mark, the regression appears with your patch for PR14401:
http://gcc.gnu.org/ml/gcc-cvs/2004-03/msg00427.html

Could you please have a look?
Comment 3 GCC Commits 2004-11-03 02:48:50 UTC
Subject: Bug 18177

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2004-11-03 02:48:45

Modified files:
	gcc/cp         : ChangeLog parser.c typeck.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/g++.dg/parse: crash13.C 
Added files:
	gcc/testsuite/g++.dg/conversion: const3.C 
	gcc/testsuite/g++.dg/template: crash25.C typedef2.C 

Log message:
	PR c++/18124
	* parser.c (cp_parser_type_parameter): Robustify.
	
	PR c++/18155
	* parser.c (cp_parser_single_declaration): Disallow template
	typedefs.
	
	PR c++/18177
	* typeck.c (build_const_cast): Use error_operand_p.
	
	PR c++/18124
	* g++.dg/template/crash25.C: New test.
	
	PR c++/18155
	* g++.dg/template/typedef2.C: New test.
	* g++.dg/parse/crash13.C: Adjust error markers.
	
	PR c++/18177
	* g++.dg/conversion/const3.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4471&r2=1.4472
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parser.c.diff?cvsroot=gcc&r1=1.275&r2=1.276
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.591&r2=1.592
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4537&r2=1.4538
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/conversion/const3.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/crash13.C.diff?cvsroot=gcc&r1=1.2&r2=1.3
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/crash25.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/typedef2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 4 Mark Mitchell 2004-11-03 02:56:39 UTC
Fixed in GCC 4.0.
Comment 5 GCC Commits 2005-10-11 00:39:31 UTC
Subject: Bug 18177

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	reichelt@gcc.gnu.org	2005-10-11 00:39:26

Modified files:
	gcc/cp         : ChangeLog cvt.c name-lookup.c typeck.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/lookup: crash5.C forscope2.C 
	gcc/testsuite/g++.dg/conversion: const3.C 

Log message:
	Backport:
	2004-09-23  Andrew Pinski  <pinskia@physics.uc.edu>
	PR c++/17618
	* cvt.c (cp_convert_to_pointer): Return early when the type is
	an error_mark_node.
	
	2004-05-22  Roger Sayle  <roger@eyesopen.com>
	* name-lookup.c (check_for_out_of_scope_variable): Avoid ICE by
	returning when TREE_TYPE is error_mark_node.
	* typeck.c (require_complete_type): Return error_mark_node if
	value's type is an error_mark_node.
	
	2004-11-02  Mark Mitchell  <mark@codesourcery.com>
	PR c++/18177
	* typeck.c (build_const_cast): Use error_operand_p.
	
	2004-09-23  Andrew Pinski  <pinskia@physics.uc.edu>
	PR c++/17618
	* g++.dg/lookup/crash5.C: New test.
	
	2004-05-22  Wolfgang Bangerth  <bangerth@dealii.org>
	Roger Sayle  <roger@eyesopen.com>
	* g++.dg/lookup/forscope2.C: New test case.
	
	2004-11-02  Mark Mitchell  <mark@codesourcery.com>
	PR c++/18177
	* g++.dg/conversion/const3.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.245&r2=1.3892.2.246
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cvt.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.151.4.4&r2=1.151.4.5
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.34.2.25&r2=1.34.2.26
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.519.2.30&r2=1.519.2.31
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.440&r2=1.3389.2.441
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/crash5.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.70.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/forscope2.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.76.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/conversion/const3.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.48.1