This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 10278
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 31 Mar 2003 12:03:25 -0800
- Subject: C++ PATCH: PR 10278
- Reply-to: mark at codesourcery dot com
This fixes a crash while outputting an error message in the C++ front
end on the 3.3 branch.
Due to the new parser, we'll need a different fix for 3.4; I'm working
on that too.
Tested on i686-pc-linux-gnu, applied on the branch.
--
Mark Mitchell
CodeSourcery, LLC
mark at codesourcery dot com
2003-03-31 Mark Mitchell <mark at codesourcery dot com>
PR c++/10278
* spew.c (yyerror): Avoid crashing at all costs.
2003-03-31 Mark Mitchell <mark at codesourcery dot com>
PR c++/10278
* g++.dg/parse/crash2.C: New test.
Index: cp/spew.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/Attic/spew.c,v
retrieving revision 1.76.2.1
diff -c -5 -p -r1.76.2.1 spew.c
*** cp/spew.c 27 Mar 2003 12:27:15 -0000 1.76.2.1
--- cp/spew.c 31 Mar 2003 19:36:51 -0000
*************** yyerror (msgid)
*** 1523,1538 ****
if (last_token == CPP_EOF)
error ("%s at end of input", string);
else if (last_token == CPP_CHAR || last_token == CPP_WCHAR)
{
! unsigned int val = TREE_INT_CST_LOW (yylval.ttype);
! const char *const ell = (last_token == CPP_CHAR) ? "" : "L";
! if (val <= UCHAR_MAX && ISGRAPH (val))
! error ("%s before %s'%c'", string, ell, val);
else
! error ("%s before %s'\\x%x'", string, ell, val);
}
else if (last_token == CPP_STRING
|| last_token == CPP_WSTRING)
error ("%s before string constant", string);
else if (last_token == CPP_NUMBER)
--- 1523,1543 ----
if (last_token == CPP_EOF)
error ("%s at end of input", string);
else if (last_token == CPP_CHAR || last_token == CPP_WCHAR)
{
! if (yylval.ttype && TREE_CODE (yylval.ttype) == INTEGER_CST)
! {
! unsigned int val = TREE_INT_CST_LOW (yylval.ttype);
! const char *const ell = (last_token == CPP_CHAR) ? "" : "L";
! if (val <= UCHAR_MAX && ISGRAPH (val))
! error ("%s before %s'%c'", string, ell, val);
! else
! error ("%s before %s'\\x%x'", string, ell, val);
! }
else
! error ("%s", string);
}
else if (last_token == CPP_STRING
|| last_token == CPP_WSTRING)
error ("%s before string constant", string);
else if (last_token == CPP_NUMBER)
Index: testsuite/g++.dg/parse/crash2.C
===================================================================
RCS file: testsuite/g++.dg/parse/crash2.C
diff -N testsuite/g++.dg/parse/crash2.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/parse/crash2.C 31 Mar 2003 19:36:56 -0000
***************
*** 0 ****
--- 1,7 ----
+ /* { dg-do compile } */
+ int main(void)
+ {
+ char x, y;
+ if ('A' == x) && ('B' == y)) { } /* { dg-error "parse error" } */
+ if (x == 'A') && (y == 'B')) { }
+ }