From patchwork Fri Mar 11 22:54:41 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 86463 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]) by ozlabs.org (Postfix) with SMTP id B87F6B6FC6 for ; Sat, 12 Mar 2011 09:54:55 +1100 (EST) Received: (qmail 11683 invoked by alias); 11 Mar 2011 22:54:54 -0000 Received: (qmail 11675 invoked by uid 22791); 11 Mar 2011 22:54:54 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 11 Mar 2011 22:54:44 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p2BMshmo017258 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 11 Mar 2011 17:54:43 -0500 Received: from [127.0.0.1] (ovpn-113-58.phx2.redhat.com [10.3.113.58]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p2BMsfx9022385 for ; Fri, 11 Mar 2011 17:54:41 -0500 Message-ID: <4D7AA831.1060801@redhat.com> Date: Fri, 11 Mar 2011 17:54:41 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/47144 (accepts-invalid with type definition in template argument) 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 G++ was oddly accepting this testcase even though it uses a name which is not defined anywhere. This turns out to be because when we see the struct B { } we commit to all tentative parses. We happened to be in the middle of testing whether A<...>::SomeNonSense is a constructor declarator, so when we decide that in fact it isn't, we try to abort the tentative parse, but we've already committed to it, so the effect is to just skip over those tokens and ignore them. I'll add a sanity check to cp_parser_abort_tentative_parse in 4.7, but not 4.6. In any case, prohibiting the type definition avoids this issue. Tested x86_64-pc-linux-gnu, applied to trunk. commit a338090ba7d290167871e4fb070bb69870498305 Author: Jason Merrill Date: Fri Mar 11 17:27:43 2011 -0500 PR c++/47144 * parser.c (cp_parser_template_type_arg): Set type_definition_forbidden_message. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 7e9b286..4260f6d 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -15685,7 +15685,13 @@ static tree cp_parser_type_id (cp_parser *parser) static tree cp_parser_template_type_arg (cp_parser *parser) { - return cp_parser_type_id_1 (parser, true, false); + tree r; + const char *saved_message = parser->type_definition_forbidden_message; + parser->type_definition_forbidden_message + = G_("types may not be defined in template arguments"); + r = cp_parser_type_id_1 (parser, true, false); + parser->type_definition_forbidden_message = saved_message; + return r; } static tree cp_parser_trailing_type_id (cp_parser *parser) diff --git a/gcc/testsuite/g++.dg/parse/no-type-defn1.C b/gcc/testsuite/g++.dg/parse/no-type-defn1.C new file mode 100644 index 0000000..9e89957 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/no-type-defn1.C @@ -0,0 +1,5 @@ +// PR c++/47144 + +template struct A { }; +A< struct B { }* >::SomeNonSense // { dg-error "types may not be defined" } +int y;