From patchwork Tue Aug 28 00:20:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 962685 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-484538-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="MtBLrgQY"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41zpBs7058z9s47 for ; Tue, 28 Aug 2018 09:34:43 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=guhVpWZj/OSp IhLNFkxXLuweqGUE8mg8rAJQ9VVyV7U6rwsnIzTU7c2JNPZOijkkbQ3iuiDuqXaZ UuFQW26iicv/4WAHx38aarKh+b/tS4HG4IPGlSbhtznPjMo5FOYSqQczBv6QYpZm 7v7+wIZdHSZ2q5GtuPmAp1jzRM7vMUE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=I5U2ykOhVJBVsuDbMC 2rVnJXwlQ=; b=MtBLrgQYpHvqJwe2dPyy/PLjqJQ8jI7zm+FCneWrvw0Pz1Dt1/ eONP5Llw/shGJd2ohQ7OMG90Sz9ueV7+3DdDpdblmQjbzweYW4bvsMaKx+dFnkzw 1btTIggfUqRBf1LY9Hz03CItee6PuSP2enQQAyrBXTJHwOlfURNxu40RU= Received: (qmail 19583 invoked by alias); 27 Aug 2018 23:34:35 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 19573 invoked by uid 89); 27 Aug 2018 23:34:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 27 Aug 2018 23:34:33 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 69751356C5 for ; Mon, 27 Aug 2018 23:34:32 +0000 (UTC) Received: from c64.redhat.com (ovpn-112-25.phx2.redhat.com [10.3.112.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77B648B16F; Mon, 27 Aug 2018 23:34:31 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [committed] C++: fix-it hint for missing "typename" (PR c++/63392) Date: Mon, 27 Aug 2018 20:20:47 -0400 Message-Id: <1535415647-65362-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes This patch adds a fix-it hint to missing "typename" errors in the C++ frontend, suggesting the insertion of "typename ". This addresses part of PR c++/63392; however it does not improve the error-recovery for such cases. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu; adds 9 PASS results to g++.sum. Committed to trunk as r263899. gcc/cp/ChangeLog: PR c++/63392 * parser.c (cp_parser_diagnose_invalid_type_name): Add fix-it hint. gcc/testsuite/ChangeLog: PR c++/63392 * g++.dg/diagnostic/missing-typename.C: New test. --- gcc/cp/parser.c | 6 ++++-- gcc/testsuite/g++.dg/diagnostic/missing-typename.C | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/diagnostic/missing-typename.C diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index e869c8e..6a677aa 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -3406,8 +3406,10 @@ cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree id, else if (TYPE_P (parser->scope) && dependent_scope_p (parser->scope)) { + gcc_rich_location richloc (location); + richloc.add_fixit_insert_before ("typename "); if (TREE_CODE (parser->scope) == TYPENAME_TYPE) - error_at (location, + error_at (&richloc, "need % before %<%T::%D::%E%> because " "%<%T::%D%> is a dependent scope", TYPE_CONTEXT (parser->scope), @@ -3416,7 +3418,7 @@ cp_parser_diagnose_invalid_type_name (cp_parser *parser, tree id, TYPE_CONTEXT (parser->scope), TYPENAME_TYPE_FULLNAME (parser->scope)); else - error_at (location, "need % before %<%T::%E%> because " + error_at (&richloc, "need % before %<%T::%E%> because " "%qT is a dependent scope", parser->scope, id, parser->scope); } diff --git a/gcc/testsuite/g++.dg/diagnostic/missing-typename.C b/gcc/testsuite/g++.dg/diagnostic/missing-typename.C new file mode 100644 index 0000000..21d1ed1 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/missing-typename.C @@ -0,0 +1,12 @@ +// fix-it hint for missing "typename" (PR c++/63392) +// { dg-options "-fdiagnostics-show-caret" } + +template +class test_1 { + T::type x; // { dg-error "need 'typename' before 'T::type' because 'T' is a dependent scope" } + /* { dg-begin-multiline-output "" } + T::type x; + ^ + typename + { dg-end-multiline-output "" } */ +};