From patchwork Fri Feb 7 19:46:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1235111 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519150-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=xiQt2Yz/; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Q6Bgwgts; dkim-atps=neutral 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 48Dm6L6Pk9z9sRX for ; Sat, 8 Feb 2020 06:47:18 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:content-type :content-transfer-encoding; q=dns; s=default; b=A/GjMkMNTn68Jbmc /TB+q1oHGWutOCLy01X4xTcxNkcTI9ZINgyEGU12SAQyaT0SKXvKpSYfoXViqCwF vWbFSJvO+N3H/UGLN07tepxg1Bw7Ekj7IzvmWyOQU8bcd+VhpFBIXLi9qxvZgVkZ 5T8NRbEiEAsrmn3ir860q7ia85c= 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:from :to:subject:date:message-id:content-type :content-transfer-encoding; s=default; bh=aP8MjW2gVVegzht4QrxXlD gsqIQ=; b=xiQt2Yz/rbnGdxGoFRPvl8VJp7XluGTCPUYT+VANSFi3BsXHhdPZlM nhIk8ZJkQn0N3NphEA0uKzNdykEpF3SxeDZcy5Q1QtkkhPaMQr505eCM6QNVPzxv 8M4HRm/JDxO2y6UO/tAVXWRMdvpJq25ehO0ltDJ3lDZIAV20DhBPg= Received: (qmail 8102 invoked by alias); 7 Feb 2020 19:47:09 -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 7992 invoked by uid 89); 7 Feb 2020 19:47:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 07 Feb 2020 19:47:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581104825; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=KOKWcsTRFw07xXjfRZgdX2SUiPQYNqzFxV8h894Ao8k=; b=Q6BgwgtsEq8ElmgcO8QmmJQONqQPweaiNOSRZkJOtZnER5kL6KP5RCvUiyNUFIOvdj+XGG UlzDzrnJKt4Lji+EWusNhAp5Clbd0rUiDFx+fKcIjj0rCrnWqmyPCJRQQbK9eUCcIpJBuU vER8ptjGt78nwxmaXgsCT3fvR0Mq9Zg= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-415-WeMlVevTOHuxtwvqLI2-SQ-1; Fri, 07 Feb 2020 14:47:02 -0500 Received: by mail-qt1-f197.google.com with SMTP id m8so220842qta.20 for ; Fri, 07 Feb 2020 11:47:02 -0800 (PST) Received: from barrymore.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 d22sm1873736qtp.37.2020.02.07.11.46.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Feb 2020 11:47:00 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [COMMITTED] c++: Fix use of local in constexpr if. Date: Fri, 7 Feb 2020 14:46:58 -0500 Message-Id: <20200207194658.2813-1-jason@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-IsSubscribed: yes extract_local_specs wasn't finding the mention of 'an' as a template argument because we weren't walking into template arguments. So here I changed cp_walk_subtrees to do so--only walking into template arguments in the spelling of the type or expression, not any hidden behind typedefs. The change to use typedef_variant_p avoids looking through typedefs spelled with 'typedef' as well as those spelled with 'using'. And then I removed some now-redundant code for walking into template arguments in a couple of walk_tree callbacks. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/92654 * tree.c (cp_walk_subtrees): Walk into type template arguments. * cp-tree.h (TYPE_TEMPLATE_INFO_MAYBE_ALIAS): Use typedef_variant_p instead of TYPE_ALIAS_P. * pt.c (push_template_decl_real): Likewise. (find_parameter_packs_r): Likewise. Remove dead code. * error.c (find_typenames_r): Remove dead code. --- gcc/cp/cp-tree.h | 2 +- gcc/cp/error.c | 6 --- gcc/cp/pt.c | 40 ++++--------------- gcc/cp/tree.c | 5 +++ .../g++.dg/cpp1z/constexpr-if-lambda2.C | 12 ++++++ 5 files changed, 25 insertions(+), 40 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/constexpr-if-lambda2.C base-commit: c8dd2446f597e6d1581414a9c02ff329285181a9 diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index b8035b4360d..c46d1e92b3b 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -3482,7 +3482,7 @@ struct GTY(()) lang_decl { for the alias template (if any). Otherwise behave as TYPE_TEMPLATE_INFO. */ #define TYPE_TEMPLATE_INFO_MAYBE_ALIAS(NODE) \ - (TYPE_ALIAS_P (NODE) \ + (typedef_variant_p (NODE) \ ? TYPE_ALIAS_TEMPLATE_INFO (NODE) \ : TYPE_TEMPLATE_INFO (NODE)) diff --git a/gcc/cp/error.c b/gcc/cp/error.c index 973b3034e12..ab8638fbaec 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -1526,12 +1526,6 @@ find_typenames_r (tree *tp, int *walk_subtrees, void *data) if (mv && (mv == *tp || !d->p_set->add (mv))) vec_safe_push (d->typenames, mv); - /* Search into class template arguments, which cp_walk_subtrees - doesn't do. */ - if (CLASS_TYPE_P (*tp) && CLASSTYPE_TEMPLATE_INFO (*tp)) - cp_walk_tree (&CLASSTYPE_TI_ARGS (*tp), find_typenames_r, - data, d->p_set); - return NULL_TREE; } diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 01bade85cdf..2fb52caa5d4 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -3818,9 +3818,12 @@ find_parameter_packs_r (tree *tp, int *walk_subtrees, void* data) (struct find_parameter_pack_data*)data; bool parameter_pack_p = false; - /* Handle type aliases/typedefs. */ - if (TYPE_ALIAS_P (t)) + /* Don't look through typedefs; we are interested in whether a + parameter pack is actually written in the expression/type we're + looking at, not the target type. */ + if (TYPE_P (t) && typedef_variant_p (t)) { + /* But do look at arguments for an alias template. */ if (tree tinfo = TYPE_ALIAS_TEMPLATE_INFO (t)) cp_walk_tree (&TI_ARGS (tinfo), &find_parameter_packs_r, @@ -3903,27 +3906,13 @@ find_parameter_packs_r (tree *tp, int *walk_subtrees, void* data) &find_parameter_packs_r, ppd, ppd->visited); /* This switch statement will return immediately if we don't find a - parameter pack. */ + parameter pack. ??? Should some of these be in cp_walk_subtrees? */ switch (TREE_CODE (t)) { - case TEMPLATE_PARM_INDEX: - return NULL_TREE; - case BOUND_TEMPLATE_TEMPLATE_PARM: /* Check the template itself. */ cp_walk_tree (&TREE_TYPE (TYPE_TI_TEMPLATE (t)), &find_parameter_packs_r, ppd, ppd->visited); - /* Check the template arguments. */ - cp_walk_tree (&TYPE_TI_ARGS (t), &find_parameter_packs_r, ppd, - ppd->visited); - *walk_subtrees = 0; - return NULL_TREE; - - case TEMPLATE_TYPE_PARM: - case TEMPLATE_TEMPLATE_PARM: - return NULL_TREE; - - case PARM_DECL: return NULL_TREE; case DECL_EXPR: @@ -3932,20 +3921,6 @@ find_parameter_packs_r (tree *tp, int *walk_subtrees, void* data) *walk_subtrees = 0; return NULL_TREE; - case RECORD_TYPE: - if (TYPE_PTRMEMFUNC_P (t)) - return NULL_TREE; - /* Fall through. */ - - case UNION_TYPE: - case ENUMERAL_TYPE: - if (TYPE_TEMPLATE_INFO (t)) - cp_walk_tree (&TYPE_TI_ARGS (t), - &find_parameter_packs_r, ppd, ppd->visited); - - *walk_subtrees = 0; - return NULL_TREE; - case TEMPLATE_DECL: if (!DECL_TEMPLATE_TEMPLATE_PARM_P (t)) return NULL_TREE; @@ -5794,8 +5769,7 @@ push_template_decl_real (tree decl, bool is_friend) if (check_for_bare_parameter_packs (TYPE_RAISES_EXCEPTIONS (type))) TYPE_RAISES_EXCEPTIONS (type) = NULL_TREE; } - else if (check_for_bare_parameter_packs ((TREE_CODE (decl) == TYPE_DECL - && TYPE_DECL_ALIAS_P (decl)) + else if (check_for_bare_parameter_packs (is_typedef_decl (decl) ? DECL_ORIGINAL_TYPE (decl) : TREE_TYPE (decl))) { diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 21f733af486..fda630790a2 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -4918,6 +4918,11 @@ cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func, } \ while (0) + if (TYPE_P (*tp)) + /* Walk into template args without looking through typedefs. */ + if (tree ti = TYPE_TEMPLATE_INFO_MAYBE_ALIAS (*tp)) + WALK_SUBTREE (TI_ARGS (ti)); + /* Not one of the easy cases. We must explicitly go through the children. */ result = NULL_TREE; diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if-lambda2.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if-lambda2.C new file mode 100644 index 00000000000..fb26ac716d4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if-lambda2.C @@ -0,0 +1,12 @@ +// PR c++/92654 +// { dg-do compile { target c++17 } } + +template struct C; +template +void am() { + [](auto an) + { + if constexpr (C::ap) ; // { dg-error "constant" } + }(42); +} +void fn() { am<42>(); }