From patchwork Thu Feb 18 05:05:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 584498 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 33A34140317 for ; Thu, 18 Feb 2016 16:05:29 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=cXZHlqdA; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=l+IwACs75M3nFIvL7xyWEl5YZPqfpMIUS+7Jd1zwJbzbAJXm7i KEYK7f3elO7gebpawH3Yv++On2xVZbDUmZemSZ7q70s3rQNyY2Q1lkUt595UrBFx Wh9uwB7QgH2lC2VLCWTtXZRQrbuu7b6oVb8CNOxzr6SuQqeLhLw7/O5LU= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=9WAI1+XbvkmmnfaGU4QXNjfcvSQ=; b=cXZHlqdA2R0fVYB1Hrxg WLXVNrHT+7RiikeNnoL5vq+t2BkGh7qpjUmk27C1KnVZt+gyIyC30LrfEGvWBdZw g+hsRSe/ZNLi87tSUYoHTHH0OK11NbWvpLSO7xlT+mUA4liejT0J04UIC2hkXNTz ood2WbKPO19pGYKVRG/860E= Received: (qmail 27954 invoked by alias); 18 Feb 2016 05:05:22 -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 27840 invoked by uid 89); 18 Feb 2016 05:05:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=TREE_CONSTANT, tree_constant, positions, detection 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 18 Feb 2016 05:05:08 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 6459551D for ; Thu, 18 Feb 2016 05:05:06 +0000 (UTC) Received: from [10.10.116.30] (ovpn-116-30.rdu2.redhat.com [10.10.116.30]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1I555to019931 for ; Thu, 18 Feb 2016 00:05:06 -0500 To: gcc-patches List From: Jason Merrill Subject: C++ PATCH for c++/68585 (wrong error with constexpr list-initialization) Message-ID: <56C55101.7000006@redhat.com> Date: Thu, 18 Feb 2016 00:05:05 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 init_subob_ctx changed value, and then evaluating value didn't change it, so we were thinking nothing had changed. Fixed by remembering the value from before init_subob_ctx. Tested x86_64-pc-linux-gnu, applying to trunk and 5. commit afc049e2b450d7cccc10e62e3c0112e30a9600d6 Author: Jason Merrill Date: Wed Feb 17 16:20:00 2016 -0500 PR c++/68585 * constexpr.c (cxx_eval_bare_aggregate): Fix 'changed' detection. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 11037fb..0eedfca 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -2234,6 +2234,7 @@ cxx_eval_bare_aggregate (const constexpr_ctx *ctx, tree t, bool side_effects_p = false; FOR_EACH_CONSTRUCTOR_ELT (v, i, index, value) { + tree orig_value = value; constexpr_ctx new_ctx; init_subob_ctx (ctx, new_ctx, index, value); if (new_ctx.ctor != ctx->ctor) @@ -2246,7 +2247,7 @@ cxx_eval_bare_aggregate (const constexpr_ctx *ctx, tree t, /* Don't VERIFY_CONSTANT here. */ if (ctx->quiet && *non_constant_p) break; - if (elt != value) + if (elt != orig_value) changed = true; if (!TREE_CONSTANT (elt)) diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist9.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist9.C new file mode 100644 index 0000000..239b91e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist9.C @@ -0,0 +1,41 @@ +// PR c++/68585 +// { dg-do compile { target c++11 } } + +template + struct array + { + T _M_data[N]; + }; + +template + struct integer_sequence + { + }; + +struct Pos +{ + unsigned l; +}; + +template +constexpr array make_grid_position(integer_sequence) +{ + return {{ Pos{Ints}... }}; +} + +constexpr array make_grid_positions() +{ + return make_grid_position(integer_sequence{}); +} + +template +void generate_sudoku(T) +{ + constexpr auto positions = make_grid_positions(); // fail +} + +int main() +{ + constexpr auto positions = make_grid_positions(); // ok + generate_sudoku(1); +}