{"id":818651,"url":"http://patchwork.ozlabs.org/api/patches/818651/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/1506434179-2736-2-git-send-email-dmalcolm@redhat.com/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1506434179-2736-2-git-send-email-dmalcolm@redhat.com>","list_archive_url":null,"date":"2017-09-26T13:56:18","name":"[1/2] C++: avoid partial duplicate implementation of cp_parser_error","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"71da3a0372b11ccd535506a3edbee9318e7ed747","submitter":{"id":24465,"url":"http://patchwork.ozlabs.org/api/people/24465/?format=json","name":"David Malcolm","email":"dmalcolm@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/1506434179-2736-2-git-send-email-dmalcolm@redhat.com/mbox/","series":[{"id":5146,"url":"http://patchwork.ozlabs.org/api/series/5146/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=5146","date":"2017-09-26T13:56:17","name":"Re: [PATCH] C/C++: add fix-it hints for various missing symbols","version":1,"mbox":"http://patchwork.ozlabs.org/series/5146/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/818651/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/818651/checks/","tags":{},"related":[],"headers":{"Return-Path":"<gcc-patches-return-462983-incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","mailing list gcc-patches@gcc.gnu.org"],"Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org\n\t(client-ip=209.132.180.131; helo=sourceware.org;\n\tenvelope-from=gcc-patches-return-462983-incoming=patchwork.ozlabs.org@gcc.gnu.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org\n\theader.b=\"LShkr6MR\"; dkim-atps=neutral","sourceware.org; auth=none","ext-mx10.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx10.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=dmalcolm@redhat.com"],"Received":["from sourceware.org (server1.sourceware.org [209.132.180.131])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3y1jDN5l0Yz9tXK\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 26 Sep 2017 23:56:36 +1000 (AEST)","(qmail 123479 invoked by alias); 26 Sep 2017 13:56:21 -0000","(qmail 123365 invoked by uid 89); 26 Sep 2017 13:56:20 -0000","from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by\n\tsourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP;\n\tTue, 26 Sep 2017 13:56:17 +0000","from smtp.corp.redhat.com\n\t(int-mx01.intmail.prod.int.phx2.redhat.com\n\t[10.5.11.11])\t(using TLSv1.2 with cipher AECDH-AES256-SHA\n\t(256/256 bits))\t(No client certificate requested)\tby\n\tmx1.redhat.com (Postfix) with ESMTPS id 187835F742\tfor\n\t<gcc-patches@gcc.gnu.org>; Tue, 26 Sep 2017 13:56:16 +0000 (UTC)","from c64.redhat.com (ovpn-112-11.phx2.redhat.com [10.3.112.11])\tby\n\tsmtp.corp.redhat.com (Postfix) with ESMTP id 2E33F6F950;\n\tTue, 26 Sep 2017 13:56:12 +0000 (UTC)"],"DomainKey-Signature":"a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:from\n\t:to:cc:subject:date:message-id:in-reply-to:references; q=dns; s=\n\tdefault; b=xVeTTpcnNLgUZyrGWOB3ccmsODtXc5HfRVs1HDrMgzQ06o1mJp29n\n\t9Aw70JSxolWGCZlLuCvvM3eCmzZvuikrjkO8IuT1sFlf9Vp1+l/2UVNP6x0+uJuJ\n\tXhlXetbM5qRbe19ULbPA0M9Pn1cHulkiFZU5YPaE/qNIt8wm6X5Wk4=","DKIM-Signature":"v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id\n\t:list-unsubscribe:list-archive:list-post:list-help:sender:from\n\t:to:cc:subject:date:message-id:in-reply-to:references; s=\n\tdefault; bh=p9mwM3MB90uRFSCcnYaAvdKhN2s=; b=LShkr6MRJ2zt3CPx4B01\n\tjzMpAupXaTXScbhLk9k4AV7v8GSyERgbLMWgXIrboeyAZ8/JeZ33jq/Hc9r25qOP\n\tzOPnAkChqdh5MU3ed7MEv3yxFIYJ7N6PsPfaPCxieamBRbZQbwDLahIl6XybgxGe\n\txMtRtLy8fpMkPItRPhj8NB0=","Mailing-List":"contact gcc-patches-help@gcc.gnu.org; run by ezmlm","Precedence":"bulk","List-Id":"<gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<mailto:gcc-patches-unsubscribe-incoming=patchwork.ozlabs.org@gcc.gnu.org>","List-Archive":"<http://gcc.gnu.org/ml/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-help@gcc.gnu.org>","Sender":"gcc-patches-owner@gcc.gnu.org","X-Virus-Found":"No","X-Spam-SWARE-Status":"No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0,\n\tGIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD,\n\tSPF_HELO_PASS autolearn=ham version=3.3.2 spammy=LINE","X-HELO":"mx1.redhat.com","DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 187835F742","From":"David Malcolm <dmalcolm@redhat.com>","To":"Jeff Law <law@redhat.com>,\tgcc-patches@gcc.gnu.org","Cc":"David Malcolm <dmalcolm@redhat.com>","Subject":"[PATCH 1/2] C++: avoid partial duplicate implementation of\n\tcp_parser_error","Date":"Tue, 26 Sep 2017 09:56:18 -0400","Message-Id":"<1506434179-2736-2-git-send-email-dmalcolm@redhat.com>","In-Reply-To":"<1506434179-2736-1-git-send-email-dmalcolm@redhat.com>","References":"<1499107059-28855-1-git-send-email-dmalcolm@redhat.com>\n\t<1506434179-2736-1-git-send-email-dmalcolm@redhat.com>","X-IsSubscribed":"yes"},"content":"In r251026 (aka 3fe34694f0990d1d649711ede0326497f8a849dc,\n\"C/C++: show pertinent open token when missing a close token\")\nI copied part of cp_parser_error into cp_parser_required_error,\nleading to duplication of code.\n\nThis patch eliminates this duplication by merging the two copies of the\ncode into a new cp_parser_error_1 subroutine.\n\nDoing so removes an indentation level, making the patch appear to have\nmore churn than it really does.\n\nThe patch also undoes the change to g++.dg/parse/pragma2.C, as the\nold behavior is restored.\n\nSuccessfully bootstrapped & regrtested on x86_64-pc-linux-gnu.\n\nOK for trunk?\n\ngcc/cp/ChangeLog:\n\t* parser.c (get_matching_symbol): Move to before...\n\t(cp_parser_error): Split out into...\n\t(cp_parser_error_1): ...this new function, merging in content\n\tfrom...\n\t(cp_parser_required_error): ...here.  Eliminate partial duplicate\n\tof body of cp_parser_error in favor of a call to the new\n\tcp_parser_error_1 helper function.\n\ngcc/testsuite/ChangeLog:\n\t* g++.dg/parse/pragma2.C: Update to reflect reinstatement of the\n\t\"#pragma is not allowed here\" error.\n---\n gcc/cp/parser.c                      | 169 ++++++++++++++++++++---------------\n gcc/testsuite/g++.dg/parse/pragma2.C |   4 +-\n 2 files changed, 97 insertions(+), 76 deletions(-)","diff":"diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c\nindex 25b91df..56d9442 100644\n--- a/gcc/cp/parser.c\n+++ b/gcc/cp/parser.c\n@@ -2767,53 +2767,116 @@ cp_lexer_peek_conflict_marker (cp_lexer *lexer, enum cpp_ttype tok1_kind,\n   return true;\n }\n \n-/* If not parsing tentatively, issue a diagnostic of the form\n+/* Get a description of the matching symbol to TOKEN_DESC e.g. \"(\" for\n+   RT_CLOSE_PAREN.  */\n+\n+static const char *\n+get_matching_symbol (required_token token_desc)\n+{\n+  switch (token_desc)\n+    {\n+    default:\n+      gcc_unreachable ();\n+      return \"\";\n+    case RT_CLOSE_BRACE:\n+      return \"{\";\n+    case RT_CLOSE_PAREN:\n+      return \"(\";\n+    }\n+}\n+\n+/* Subroutine of cp_parser_error and cp_parser_required_error.\n+\n+   Issue a diagnostic of the form\n       FILE:LINE: MESSAGE before TOKEN\n    where TOKEN is the next token in the input stream.  MESSAGE\n    (specified by the caller) is usually of the form \"expected\n-   OTHER-TOKEN\".  */\n+   OTHER-TOKEN\".\n+\n+   This bypasses the check for tentative passing, and potentially\n+   adds material needed by cp_parser_required_error.\n+\n+   If MISSING_TOKEN_DESC is not RT_NONE, and MATCHING_LOCATION is not\n+   UNKNOWN_LOCATION, then we have an unmatched symbol at\n+   MATCHING_LOCATION; highlight this secondary location.  */\n \n static void\n-cp_parser_error (cp_parser* parser, const char* gmsgid)\n+cp_parser_error_1 (cp_parser* parser, const char* gmsgid,\n+\t\t   required_token missing_token_desc,\n+\t\t   location_t matching_location)\n {\n-  if (!cp_parser_simulate_error (parser))\n+  cp_token *token = cp_lexer_peek_token (parser->lexer);\n+  /* This diagnostic makes more sense if it is tagged to the line\n+     of the token we just peeked at.  */\n+  cp_lexer_set_source_position_from_token (token);\n+\n+  if (token->type == CPP_PRAGMA)\n     {\n-      cp_token *token = cp_lexer_peek_token (parser->lexer);\n-      /* This diagnostic makes more sense if it is tagged to the line\n-\t of the token we just peeked at.  */\n-      cp_lexer_set_source_position_from_token (token);\n+      error_at (token->location,\n+\t\t\"%<#pragma%> is not allowed here\");\n+      cp_parser_skip_to_pragma_eol (parser, token);\n+      return;\n+    }\n \n-      if (token->type == CPP_PRAGMA)\n+  /* If this is actually a conflict marker, report it as such.  */\n+  if (token->type == CPP_LSHIFT\n+      || token->type == CPP_RSHIFT\n+      || token->type == CPP_EQ_EQ)\n+    {\n+      location_t loc;\n+      if (cp_lexer_peek_conflict_marker (parser->lexer, token->type, &loc))\n \t{\n-\t  error_at (token->location,\n-\t\t    \"%<#pragma%> is not allowed here\");\n-\t  cp_parser_skip_to_pragma_eol (parser, token);\n+\t  error_at (loc, \"version control conflict marker in file\");\n \t  return;\n \t}\n+    }\n \n-      /* If this is actually a conflict marker, report it as such.  */\n-      if (token->type == CPP_LSHIFT\n-\t  || token->type == CPP_RSHIFT\n-\t  || token->type == CPP_EQ_EQ)\n-\t{\n-\t  location_t loc;\n-\t  if (cp_lexer_peek_conflict_marker (parser->lexer, token->type, &loc))\n-\t    {\n-\t      error_at (loc, \"version control conflict marker in file\");\n-\t      return;\n-\t    }\n-\t}\n+  gcc_rich_location richloc (input_location);\n+\n+  bool added_matching_location = false;\n+\n+  if (missing_token_desc != RT_NONE)\n+    {\n+      /* If matching_location != UNKNOWN_LOCATION, highlight it.\n+\t Attempt to consolidate diagnostics by printing it as a\n+\tsecondary range within the main diagnostic.  */\n+      if (matching_location != UNKNOWN_LOCATION)\n+\tadded_matching_location\n+\t  = richloc.add_location_if_nearby (matching_location);\n+    }\n+\n+  /* Actually emit the error.  */\n+  c_parse_error (gmsgid,\n+\t\t /* Because c_parser_error does not understand\n+\t\t    CPP_KEYWORD, keywords are treated like\n+\t\t    identifiers.  */\n+\t\t (token->type == CPP_KEYWORD ? CPP_NAME : token->type),\n+\t\t token->u.value, token->flags, &richloc);\n \n-      rich_location richloc (line_table, input_location);\n-      c_parse_error (gmsgid,\n-\t\t     /* Because c_parser_error does not understand\n-\t\t\tCPP_KEYWORD, keywords are treated like\n-\t\t\tidentifiers.  */\n-\t\t     (token->type == CPP_KEYWORD ? CPP_NAME : token->type),\n-\t\t     token->u.value, token->flags, &richloc);\n+  if (missing_token_desc != RT_NONE)\n+    {\n+      /* If we weren't able to consolidate matching_location, then\n+\t print it as a secondary diagnostic.  */\n+      if (matching_location != UNKNOWN_LOCATION\n+\t  && !added_matching_location)\n+\tinform (matching_location, \"to match this %qs\",\n+\t\tget_matching_symbol (missing_token_desc));\n     }\n }\n \n+/* If not parsing tentatively, issue a diagnostic of the form\n+      FILE:LINE: MESSAGE before TOKEN\n+   where TOKEN is the next token in the input stream.  MESSAGE\n+   (specified by the caller) is usually of the form \"expected\n+   OTHER-TOKEN\".  */\n+\n+static void\n+cp_parser_error (cp_parser* parser, const char* gmsgid)\n+{\n+  if (!cp_parser_simulate_error (parser))\n+    cp_parser_error_1 (parser, gmsgid, RT_NONE, UNKNOWN_LOCATION);\n+}\n+\n /* Issue an error about name-lookup failing.  NAME is the\n    IDENTIFIER_NODE DECL is the result of\n    the lookup (as returned from cp_parser_lookup_name).  DESIRED is\n@@ -27960,24 +28023,6 @@ cp_parser_friend_p (const cp_decl_specifier_seq *decl_specifiers)\n   return decl_spec_seq_has_spec_p (decl_specifiers, ds_friend);\n }\n \n-/* Get a description of the matching symbol to TOKEN_DESC e.g. \"(\" for\n-   RT_CLOSE_PAREN.  */\n-\n-static const char *\n-get_matching_symbol (required_token token_desc)\n-{\n-  switch (token_desc)\n-    {\n-    default:\n-      gcc_unreachable ();\n-      return \"\";\n-    case RT_CLOSE_BRACE:\n-      return \"{\";\n-    case RT_CLOSE_PAREN:\n-      return \"(\";\n-    }\n-}\n-\n /* Issue an error message indicating that TOKEN_DESC was expected.\n    If KEYWORD is true, it indicated this function is called by\n    cp_parser_require_keword and the required token can only be\n@@ -28155,31 +28200,7 @@ cp_parser_required_error (cp_parser *parser,\n     }\n \n   if (gmsgid)\n-    {\n-      /* Emulate rest of cp_parser_error.  */\n-      cp_token *token = cp_lexer_peek_token (parser->lexer);\n-      cp_lexer_set_source_position_from_token (token);\n-\n-      gcc_rich_location richloc (input_location);\n-\n-      /* If matching_location != UNKNOWN_LOCATION, highlight it.\n-\t Attempt to consolidate diagnostics by printing it as a\n-\tsecondary range within the main diagnostic.  */\n-      bool added_matching_location = false;\n-      if (matching_location != UNKNOWN_LOCATION)\n-\tadded_matching_location\n-\t  = richloc.add_location_if_nearby (matching_location);\n-\n-      c_parse_error (gmsgid,\n-\t\t     (token->type == CPP_KEYWORD ? CPP_NAME : token->type),\n-\t\t     token->u.value, token->flags, &richloc);\n-\n-      /* If we weren't able to consolidate matching_location, then\n-\t print it as a secondary diagnostic.  */\n-      if (matching_location != UNKNOWN_LOCATION && !added_matching_location)\n-\tinform (matching_location, \"to match this %qs\",\n-\t\tget_matching_symbol (token_desc));\n-    }\n+    cp_parser_error_1 (parser, gmsgid, token_desc, matching_location);\n }\n \n \ndiff --git a/gcc/testsuite/g++.dg/parse/pragma2.C b/gcc/testsuite/g++.dg/parse/pragma2.C\nindex 3dc5fc1..c5616ff 100644\n--- a/gcc/testsuite/g++.dg/parse/pragma2.C\n+++ b/gcc/testsuite/g++.dg/parse/pragma2.C\n@@ -4,5 +4,5 @@\n // does not.\n int f(int x,\n #pragma interface  // { dg-error \"not allowed here\" }\n-      // { dg-bogus \"expected identifier\" \"\" { xfail *-*-* } .-1 }\n-      int y);\n+      // The parser gets confused and issues an error on the next line.\n+      int y); // { dg-bogus \"\" \"\" { xfail *-*-* } } \n","prefixes":["1/2"]}