PR c++/96329: ICE-on-invalid-code error recovery.

This patch fixes PR c++/96329 which is an ICE-on-invalid-code regression
affecting mainline.

2022-03-08  Roger Sayle  <roger@nextmovesoftware.com>

gcc/cp/ChangeLog
	PR c++/96329
	* parser.cc (cp_parser_linkage_specification): Treat the case where
	linkage is error_mark_node as "invalid linkage-specification".

gcc/testsuite/ChangeLog
	PR c++/96329
	* g++.dg/template/pr96329.C: New test case.
This commit is contained in:
Roger Sayle 2022-03-08 23:18:34 +00:00
parent d54ce4641e
commit 8ab72ec7c4
2 changed files with 7 additions and 2 deletions

View File

@ -16148,8 +16148,9 @@ cp_parser_linkage_specification (cp_parser* parser, tree prefix_attr)
/* Transform the literal into an identifier. If the literal is a
wide-character string, or contains embedded NULs, then we can't
handle it as the user wants. */
if (strlen (TREE_STRING_POINTER (linkage))
!= (size_t) (TREE_STRING_LENGTH (linkage) - 1))
if (linkage == error_mark_node
|| strlen (TREE_STRING_POINTER (linkage))
!= (size_t) (TREE_STRING_LENGTH (linkage) - 1))
{
cp_parser_error (parser, "invalid linkage-specification");
/* Assume C++ linkage. */

View File

@ -0,0 +1,4 @@
/* { dg-do compile } */
/* { dg-excess-errors "" } */
extern "C" ""a