From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 55571 invoked by alias); 17 Jan 2019 20:36:28 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 55552 invoked by uid 89); 17 Jan 2019 20:36:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=cap, HContent-Transfer-Encoding:8bit X-HELO: mail-qt1-f193.google.com Received: from mail-qt1-f193.google.com (HELO mail-qt1-f193.google.com) (209.85.160.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 17 Jan 2019 20:36:25 +0000 Received: by mail-qt1-f193.google.com with SMTP id k12so12838878qtf.7 for ; Thu, 17 Jan 2019 12:36:25 -0800 (PST) Return-Path: Received: from orpheus.redhat.com (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id a70sm46575406qkc.81.2019.01.17.12.36.22 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 17 Jan 2019 12:36:22 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] PR c++/86740, ICE with constexpr if and nested generic lambdas. Date: Thu, 17 Jan 2019 20:36:00 -0000 Message-Id: <20190117203621.29206-1-jason@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2019-01/txt/msg01030.txt.bz2 When we partially instantiate the constexpr if, we walk through its body to see what it uses from the enclosing local_specializations. That walk was overlooking the use of 'count' in the captures of the innermost lambda, because we weren't walking into the capture list. Tested x86_64-pc-linux-gnu, applying to trunk. * tree.c (cp_walk_subtrees): Handle LAMBDA_EXPR. --- gcc/cp/tree.c | 8 ++++++ gcc/testsuite/g++.dg/cpp1z/constexpr-if25.C | 27 +++++++++++++++++++++ gcc/cp/ChangeLog | 5 ++++ 3 files changed, 40 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp1z/constexpr-if25.C diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 50002161500..be33d4186f9 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -4933,6 +4933,14 @@ cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func, } break; + case LAMBDA_EXPR: + /* Don't walk into the body of the lambda, but the capture initializers + are part of the enclosing context. */ + for (tree cap = LAMBDA_EXPR_CAPTURE_LIST (*tp); cap; + cap = TREE_CHAIN (cap)) + WALK_SUBTREE (TREE_VALUE (cap)); + break; + default: return NULL_TREE; } diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if25.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if25.C new file mode 100644 index 00000000000..144139ea196 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if25.C @@ -0,0 +1,27 @@ +// PR c++/86740 +// { dg-do compile { target c++17 } } + +struct Constant +{ + static constexpr int value = 0; +}; +template +void invokeWithConstant(F &&f) +{ + f(Constant{}); +} +int foo() +{ + int count = 0; + invokeWithConstant + ([&] (auto id1) + { + invokeWithConstant + ([&] (auto id2) + { + if constexpr (id1.value == 0 && id2.value == 0) + [&] { count = 1; } (); + }); + }); + return count; +} diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 05e8566e493..01a57601f4c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-01-17 Jason Merrill + + PR c++/86740, ICE with constexpr if and nested generic lambdas. + * tree.c (cp_walk_subtrees): Handle LAMBDA_EXPR. + 2019-01-17 Paolo Carlini * decl.c (grokdeclarator): Use typespec_loc in error messages base-commit: 7e351bf905bf4b0ad84bf9dae79032f8c41f0e03 -- 2.20.1