From patchwork Mon Apr 1 21:12:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 232808 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 52E152C0128 for ; Tue, 2 Apr 2013 08:13:17 +1100 (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:content-type; q= dns; s=default; b=FQDHfcmj5NAqFOpcZpbx+MV2oo1JaZYcJZ0vl1WXl3eejT wtAFPTzLLTAktPeS4TJ3id3gu2K2fNFR/yW9YwYMnS2igAkKLT2VqR7hwRtv/wOm 4YHFVg8SZPM5P0L8RzgPHbNo/EdQkfJmZC1fj18VoK3Bx5wwhz4NfLzENiTnk= 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:content-type; s= default; bh=LWtAC/Ycpk228Ss7R+d0S4usjw4=; b=gQKhamHGjuIx06cD3kDs ieOGQIaleNaGGjzFzxWzXM/Id7mBhLmPBJACLPmIK6Q9SXvPYKpd+r56q+W/Eyfc tNYfSw2xlsuVbluy0pDbsiCkqFudALj27DDOwNyWXTR/M4KjIOUX8qtNpIZRQRVt zy17N51455LmL8P7LEDlZ/I= Received: (qmail 7442 invoked by alias); 1 Apr 2013 21:13:06 -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 7377 invoked by uid 89); 1 Apr 2013 21:12:58 -0000 X-Spam-SWARE-Status: No, score=-7.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_TM autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Mon, 01 Apr 2013 21:12:55 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r31LCsZr030344 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 1 Apr 2013 17:12:54 -0400 Received: from [10.3.113.94] (ovpn-113-94.phx2.redhat.com [10.3.113.94]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r31LCsZF014884 for ; Mon, 1 Apr 2013 17:12:54 -0400 Message-ID: <5159F855.8050403@redhat.com> Date: Mon, 01 Apr 2013 17:12:53 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Thunderbird/21.0a2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/56794 (range for and variadic template) X-Virus-Found: No We try to resolve types at template definition time if expressions don't depend on template parameters, but this testcase shows a case of dependency we weren't considering: the bounds of an array can depend on the length of the initializer. Tested x86_64-pc-linux-gnu, applying to 4.7, 4.8, trunk. commit ab873d428ec43d33d1e34567749104cc5a9544ad Author: Jason Merrill Date: Mon Apr 1 15:45:54 2013 -0400 PR c++/56794 * parser.c (cp_parser_range_for): Don't try to do auto deduction in a template if the type of the range is incomplete. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index f29e80d..05c03f4 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -9615,7 +9615,10 @@ cp_parser_range_for (cp_parser *parser, tree scope, tree init, tree range_decl) range_expr = error_mark_node; stmt = begin_range_for_stmt (scope, init); finish_range_for_decl (stmt, range_decl, range_expr); - if (!type_dependent_expression_p (range_expr) + if (range_expr != error_mark_node + && !type_dependent_expression_p (range_expr) + /* The length of an array might be dependent. */ + && COMPLETE_TYPE_P (TREE_TYPE (range_expr)) /* do_auto_deduction doesn't mess with template init-lists. */ && !BRACE_ENCLOSED_INITIALIZER_P (range_expr)) do_range_for_auto_deduction (range_decl, range_expr); diff --git a/gcc/testsuite/g++.dg/cpp0x/range-for24.C b/gcc/testsuite/g++.dg/cpp0x/range-for24.C new file mode 100644 index 0000000..b4a5b18 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/range-for24.C @@ -0,0 +1,15 @@ +// PR c++/56794 +// { dg-require-effective-target c++11 } + +template +static void Colors() +{ + static const int colors[] = { values... }; + + for(auto c: colors) { } +} + +int main() +{ + Colors<0,1,2> (); +}