From patchwork Thu May 2 21:59:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 241107 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 33C4D2C0085 for ; Fri, 3 May 2013 07:59:38 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=Z9lDCYwgO5K9FNEoVnEXfEcHQ/vKnmvjW4SMXxKgAPy VAHIn5cX31wWMDPoI6kPZ/lTcOwwONkG8c9SnjjdwR+1Pd5E7VQNYuZaavNuFV53 06tQ0Y8iDI0h2/i86P87RM4YiurvHHDuHFs++fI6Y5J1xRuZVMwTzXydcY+mTMt8 = 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 :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=F5sYOfG3S7qEnBbfv9s18gXK62E=; b=GXVD0mPwySw09lA+J GNn5GD1KtkWwUjpKWwkbjd3pERQSNIa97fO2WceoLXjBFTzkrflzLPWtSlAzJXA6 JQ7ExiIpMflwnd9thclyF96QEmzirxdqgtrbZ21Z4Q3ec5HzOzHlsr0IJlAN8vEv QNzlSXkhYdjvnyLFwA3hHACCWs= Received: (qmail 28376 invoked by alias); 2 May 2013 21:59:31 -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 28366 invoked by uid 89); 2 May 2013 21:59:31 -0000 X-Spam-SWARE-Status: No, score=-6.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, SPF_PASS, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 02 May 2013 21:59:30 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r42LxRNj024410 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 2 May 2013 21:59:28 GMT Received: from aserz7022.oracle.com (aserz7022.oracle.com [141.146.126.231]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r42LxQgD016026 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Thu, 2 May 2013 21:59:27 GMT Received: from abhmt106.oracle.com (abhmt106.oracle.com [141.146.116.58]) by aserz7022.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r42LxQam016023; Thu, 2 May 2013 21:59:26 GMT Received: from poldo4.casa (/79.52.195.116) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 02 May 2013 14:59:26 -0700 Message-ID: <5182E1BC.2040706@oracle.com> Date: Thu, 02 May 2013 23:59:24 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 14283 X-Virus-Found: No Hi, in this rather old diagnostic issue, we want to provide better error messages, spelling out template if appropriate, and also fix the column numbers (in practice location_of (id) boils down to input_location which is the right position for this kind of error message among those handled by cp_parser_diagnose_invalid_type_name). Tested x86_64-linux. Thanks, Paolo. ///////////////////////////// /cp 2013-05-02 Paolo Carlini PR c++/14283 * parser.c (cp_parser_diagnose_invalid_type_name): Improve error messages for template types and fix column number. /testsuite 2013-05-02 Paolo Carlini PR c++/14283 * g++.dg/parse/error51.C: New. * g++.dg/parse/error15.C: Adjust column numbers. Index: cp/parser.c =================================================================== --- cp/parser.c (revision 198521) +++ cp/parser.c (working copy) @@ -2872,8 +2872,16 @@ cp_parser_diagnose_invalid_type_name (cp_parser *p else if (parser->scope != error_mark_node) { if (TREE_CODE (parser->scope) == NAMESPACE_DECL) - error_at (location, "%qE in namespace %qE does not name a type", - id, parser->scope); + { + if (cp_lexer_next_token_is (parser->lexer, CPP_LESS)) + error_at (location_of (id), + "%qE in namespace %qE does not name a template type", + id, parser->scope); + else + error_at (location_of (id), + "%qE in namespace %qE does not name a type", + id, parser->scope); + } else if (CLASS_TYPE_P (parser->scope) && constructor_name_p (id, parser->scope)) { @@ -2890,8 +2898,16 @@ cp_parser_diagnose_invalid_type_name (cp_parser *p "%qT is a dependent scope", parser->scope, id, parser->scope); else if (TYPE_P (parser->scope)) - error_at (location, "%qE in %q#T does not name a type", - id, parser->scope); + { + if (cp_lexer_next_token_is (parser->lexer, CPP_LESS)) + error_at (location_of (id), + "%qE in %q#T does not name a template type", + id, parser->scope); + else + error_at (location_of (id), + "%qE in %q#T does not name a type", + id, parser->scope); + } else gcc_unreachable (); } Index: testsuite/g++.dg/parse/error15.C =================================================================== --- testsuite/g++.dg/parse/error15.C (revision 198521) +++ testsuite/g++.dg/parse/error15.C (working copy) @@ -11,9 +11,9 @@ namespace N } N::A f2; // { dg-error "1:invalid use of template-name 'N::A' without an argument list" } -N::INVALID f3; // { dg-error "1:'INVALID' in namespace 'N' does not name a type" } -N::C::INVALID f4; // { dg-error "1:'INVALID' in 'struct N::C' does not name a type" } -N::K f6; // { dg-error "1:'K' in namespace 'N' does not name a type" } +N::INVALID f3; // { dg-error "4:'INVALID' in namespace 'N' does not name a type" } +N::C::INVALID f4; // { dg-error "7:'INVALID' in 'struct N::C' does not name a type" } +N::K f6; // { dg-error "4:'K' in namespace 'N' does not name a type" } typename N::A f7; // { dg-error "13:invalid use of template-name 'N::A' without an argument list" "13" { target *-*-* } 17 } // { dg-error "17:invalid type in declaration before ';' token" "17" { target *-*-* } 17 } @@ -21,9 +21,9 @@ typename N::A f7; struct B { N::A f2; // { dg-error "3:invalid use of template-name 'N::A' without an argument list" } - N::INVALID f3; // { dg-error "3:'INVALID' in namespace 'N' does not name a type" } - N::C::INVALID f4; // { dg-error "3:'INVALID' in 'struct N::C' does not name a type" } - N::K f6; // { dg-error "3:'K' in namespace 'N' does not name a type" } + N::INVALID f3; // { dg-error "6:'INVALID' in namespace 'N' does not name a type" } + N::C::INVALID f4; // { dg-error "9:'INVALID' in 'struct N::C' does not name a type" } + N::K f6; // { dg-error "6:'K' in namespace 'N' does not name a type" } typename N::A f7; // { dg-error "15:invalid use of template-name 'N::A' without an argument list" "15" { target *-*-* } 27 } }; @@ -32,9 +32,9 @@ template struct C { N::A f2; // { dg-error "3:invalid use of template-name 'N::A' without an argument list" } - N::INVALID f3; // { dg-error "3:'INVALID' in namespace 'N' does not name a type" } - N::C::INVALID f4; // { dg-error "3:'INVALID' in 'struct N::C' does not name a type" } - N::K f6; // { dg-error "3:'K' in namespace 'N' does not name a type" } + N::INVALID f3; // { dg-error "6:'INVALID' in namespace 'N' does not name a type" } + N::C::INVALID f4; // { dg-error "9:'INVALID' in 'struct N::C' does not name a type" } + N::K f6; // { dg-error "6:'K' in namespace 'N' does not name a type" } typename N::A f7; // { dg-error "15:invalid use of template-name 'N::A' without an argument list" } }; Index: testsuite/g++.dg/parse/error51.C =================================================================== --- testsuite/g++.dg/parse/error51.C (revision 0) +++ testsuite/g++.dg/parse/error51.C (working copy) @@ -0,0 +1,13 @@ +// PR c++/14283 + +struct A +{}; + +namespace N +{} + +template struct C +{ + typedef A::template INVALID X0; // { dg-error "23:'INVALID' in 'struct A' does not name a template type" } + typedef N::template INVALID X1; // { dg-error "23:'INVALID' in namespace 'N' does not name a template type" } +};