From patchwork Fri Oct 4 02:49:04 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 280454 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 did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id F145A2C00E2 for ; Fri, 4 Oct 2013 12:49:22 +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:subject:references :in-reply-to:content-type; q=dns; s=default; b=HGCov2cgKolN49kvS YJWtTSRyr+gkg1MIbFl6knDjEmYYkZTJXnWfdVK2PkgfTZeIWomETSXrYkK0qpYC rp63lcLJMUQMK9gpAGjNZPgZ9hVjhbJgAyakCOeWFwWB/wwHlQRjrOdEO6KMjA2v CV+J2817/N/MJ6aA+lXcf7mt4o= 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:subject:references :in-reply-to:content-type; s=default; bh=RqpJPoUwcSZAkMe0MmIFGem NrD4=; b=rWF/sTLy5B1IAnL64v/frE0Ebc8HZEn2MbYUTGC2aHA36o4Qwe4B/Vj Hlz9u/HwVXF72JjfyCMD/xreuBk2lJ00TZsbCOmrx7WLhLgablnh9xCW7j5hIpor M8zhBbrLgqknKR2N79yZBI7YkDAf+qmsVs8ynkeA3Gx/6/FSiJ9c= Received: (qmail 28483 invoked by alias); 4 Oct 2013 02:49:14 -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 28469 invoked by uid 89); 4 Oct 2013 02:49:13 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 04 Oct 2013 02:49:13 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.1 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_PASS, UNPARSEABLE_RELAY autolearn=ham version=3.3.2 X-HELO: aserp1040.oracle.com Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r942n8ww011368 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 4 Oct 2013 02:49:09 GMT Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r942n75b024238 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 4 Oct 2013 02:49:07 GMT Received: from abhmt103.oracle.com (abhmt103.oracle.com [141.146.116.55]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r942n6N5002427; Fri, 4 Oct 2013 02:49:06 GMT Received: from poldo4.casa (/79.33.223.204) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 03 Oct 2013 19:49:06 -0700 Message-ID: <524E2CA0.3080701@oracle.com> Date: Fri, 04 Oct 2013 04:49:04 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.0 MIME-Version: 1.0 To: Jason Merrill , "gcc-patches@gcc.gnu.org" Subject: Re: [C++ Patch] PR 58503 References: <524D3E46.2070101@oracle.com> <524D70BD.90103@redhat.com> <524E00CA.2040109@oracle.com> <524E1CC9.7090400@redhat.com> In-Reply-To: <524E1CC9.7090400@redhat.com> X-IsSubscribed: yes Hi, On 10/04/2013 03:41 AM, Jason Merrill wrote: > Well, the permerror is saying that with -fpermissive we'll do the > lookup again at instantiation time, so a testcase that declares > begin/end between the template and the instantiation ought to work? Ah, now I see! The best approximation we have of a positive test in this context. Thus the below, lightly tested so far but the tests both pass and the patch itself isn't so different, besides type_dependent_expression_p. Thanks! Paolo. //////////////////////// /cp 2013-10-04 Paolo Carlini PR c++/58503 * parser.c (cp_parser_perform_range_for_lookup): If eventually either *begin or *end is type-dependent, return NULL_TREE. (do_range_for_auto_deduction): If cp_parser_perform_range_for_lookup returns NULL_TREE, don't actually do_auto_deduction. /testsuite 2013-10-04 Paolo Carlini PR c++/58503 * g++.dg/cpp0x/range-for26.C: New. * g++.dg/cpp0x/range-for27.C: New. Index: cp/parser.c =================================================================== --- cp/parser.c (revision 203197) +++ cp/parser.c (working copy) @@ -9960,11 +9960,15 @@ do_range_for_auto_deduction (tree decl, tree range range_temp = convert_from_reference (build_range_temp (range_expr)); iter_type = (cp_parser_perform_range_for_lookup (range_temp, &begin_dummy, &end_dummy)); - iter_decl = build_decl (input_location, VAR_DECL, NULL_TREE, iter_type); - iter_decl = build_x_indirect_ref (input_location, iter_decl, RO_NULL, - tf_warning_or_error); - TREE_TYPE (decl) = do_auto_deduction (TREE_TYPE (decl), - iter_decl, auto_node); + if (iter_type) + { + iter_decl = build_decl (input_location, VAR_DECL, NULL_TREE, + iter_type); + iter_decl = build_x_indirect_ref (input_location, iter_decl, RO_NULL, + tf_warning_or_error); + TREE_TYPE (decl) = do_auto_deduction (TREE_TYPE (decl), + iter_decl, auto_node); + } } } @@ -10171,6 +10175,11 @@ cp_parser_perform_range_for_lookup (tree range, tr *begin = *end = error_mark_node; return error_mark_node; } + else if (type_dependent_expression_p (*begin) + || type_dependent_expression_p (*end)) + /* Can happen, when, eg, in a template context, Koenig lookup + can't resolve begin/end (c++/58503). */ + return NULL_TREE; else { tree iter_type = cv_unqualified (TREE_TYPE (*begin)); Index: testsuite/g++.dg/cpp0x/range-for26.C =================================================================== --- testsuite/g++.dg/cpp0x/range-for26.C (revision 0) +++ testsuite/g++.dg/cpp0x/range-for26.C (working copy) @@ -0,0 +1,7 @@ +// PR c++/58503 +// { dg-require-effective-target c++11 } + +template void foo() +{ + for (auto i : 0) {} // { dg-error "there are no arguments" } +} Index: testsuite/g++.dg/cpp0x/range-for27.C =================================================================== --- testsuite/g++.dg/cpp0x/range-for27.C (revision 0) +++ testsuite/g++.dg/cpp0x/range-for27.C (working copy) @@ -0,0 +1,15 @@ +// PR c++/58503 +// { dg-require-effective-target c++11 } +// { dg-options "-fpermissive -w" } + +struct c { }; + +template void foo() +{ + for (auto i : c()) { } +} + +c* begin(const c&); +c* end(const c&); + +template void foo<1>();