public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mark at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/96328] [11 Regression] Single keyword "friend" makes GCC ICE in cp_lexer_previous_token, at cp/parser.c:769 since r11-891-g1dc83b460653c29f
Date: Mon, 27 Jul 2020 09:06:07 +0000	[thread overview]
Message-ID: <bug-96328-4-d1S47kcEHX@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-96328-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96328

Mark Wielaard <mark at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

--- Comment #2 from Mark Wielaard <mark at gcc dot gnu.org> ---
Only tested on the failing testcase, but this seems to fix it:

$ echo "friend" | /opt/local/install/gcc/bin/g++ -c -xc++ -
<stdin>:1:1: error: ‘friend’ used outside of class
<stdin>:2: error: expected unqualified-id at end of input

diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 0c77c20da862..9c4f6a50523c 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -781,9 +781,13 @@ static cp_token *
 cp_lexer_safe_previous_token (cp_lexer *lexer)
 {
   if (lexer->buffer)
-    if (lexer->next_token != lexer->buffer->address ())
-      return cp_lexer_previous_token (lexer);
-
+    {
+      cp_token_position tp = cp_lexer_previous_token_position (lexer);
+      while (tp->purged_p && tp != lexer->buffer->address ())
+       tp--;
+      if (tp != lexer->buffer->address ())
+       return tp;
+    }
   return NULL;
 }

@@ -2932,15 +2936,15 @@ cp_parser_error_1 (cp_parser* parser, const char*
gmsgid,
   gcc_rich_location richloc (input_location);

   bool added_matching_location = false;
+  cp_token *prev_token = cp_lexer_safe_previous_token (parser->lexer);

-  if (missing_token_desc != RT_NONE)
+  if (prev_token && missing_token_desc != RT_NONE)
     {
       /* Potentially supply a fix-it hint, suggesting to add the
         missing token immediately after the *previous* token.
         This may move the primary location within richloc.  */
       enum cpp_ttype ttype = get_required_cpp_ttype (missing_token_desc);
-      location_t prev_token_loc
-       = cp_lexer_previous_token (parser->lexer)->location;
+      location_t prev_token_loc = prev_token->location;
       maybe_suggest_missing_token_insertion (&richloc, ttype, prev_token_loc);

       /* If matching_location != UNKNOWN_LOCATION, highlight it.
@@ -2957,7 +2961,6 @@ cp_parser_error_1 (cp_parser* parser, const char* gmsgid,
      standard string literal constants defined in header files. If
      there is one, then add that as an hint to the error message. */
   name_hint h;
-  cp_token *prev_token = cp_lexer_safe_previous_token (parser->lexer);
   if (prev_token && cp_parser_is_string_literal (prev_token)
       && token->type == CPP_NAME)
     {

  parent reply	other threads:[~2020-07-27  9:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-27  3:42 [Bug c++/96328] New: Singe keyword "friend" makes GCC ICE in cp_lexer_previous_token, at cp/parser.c:769 haoxintu at gmail dot com
2020-07-27  6:44 ` [Bug c++/96328] [11 Regression] Single keyword "friend" makes GCC ICE in cp_lexer_previous_token, at cp/parser.c:769 since r11-891-g1dc83b460653c29f marxin at gcc dot gnu.org
2020-07-27  7:44 ` rguenth at gcc dot gnu.org
2020-07-27  9:06 ` mark at gcc dot gnu.org [this message]
2020-07-27  9:09 ` jakub at gcc dot gnu.org
2020-07-27  9:26 ` mark at gcc dot gnu.org
2020-07-27  9:52 ` jakub at gcc dot gnu.org
2020-07-27 10:55 ` mark at gcc dot gnu.org
2020-07-28 13:42 ` cvs-commit at gcc dot gnu.org
2020-07-28 13:46 ` jakub at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-96328-4-d1S47kcEHX@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).