From patchwork Wed Dec 2 20:58:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1409983 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=WIfcJbBW; dkim-atps=neutral Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CmWYJ364lz9sVH for ; Thu, 3 Dec 2020 07:59:13 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 95D27396E062; Wed, 2 Dec 2020 20:59:02 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by sourceware.org (Postfix) with ESMTPS id D783D396E041 for ; Wed, 2 Dec 2020 20:58:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D783D396E041 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qv1-xf31.google.com with SMTP id k3so1418248qvz.4 for ; Wed, 02 Dec 2020 12:58:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=tv0WiehzmXTEOziLWvft01G6r1qng0pyy/B3FXagAJk=; b=WIfcJbBWewxfKi3NRXVJaZMaaG+aMYMON47tsPjRXPXIldcpqot9R1uhAfxxoa4n2S yC9+Qh3Vkuru0+VaTB309hXEExKE1cPk6Db9TruNmXcLPEsq/OMjyirgcFeRA/dl6J85 GTn97I7cxrBEdprWxgfe3+d4PBQ1Q5t7gn7hss2TAMxjbj46iSUHIZGETJ9PA03pq723 UwPozCi6Q2RI3Sp2pmVFLJpbfpvA1crHDDPsd78iQlmiJ2Ed/GQtyCrITJOAzIy5Zvkc jpDEjNTs+At4qlY0ZhIXGWayai1gGUSxs6hwoif3cAW7/t0+xJ0Q3Fg1GBdqudwmpDWz OmKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=tv0WiehzmXTEOziLWvft01G6r1qng0pyy/B3FXagAJk=; b=QzV/O7lfccNznwdZc+FpL54yiX3uxIm/xjkyiIH7I5vq4pJDNKhW3q5bzLKD0Fgyma 3UV6YcDpuwnb5rKq1P0eVexQVJo/ZeGqPAPdxevCqoafF3lmjfNsnwqLIMf5+KoZByei QGPTQt7ZpPotF8Wt7fR7ibMPrCQVbZHOjV0XYPyp5VRu87e8ZRBKjXz87/5wXEj6bxPi wBQiYEQISZLMdbmQE80X7SgzQzApeU+n+7akPYzaHOtKrvLJiOlQcDZnQyztMzxEAGmW AlfL8OotJTN0wshvXMnu3w9a4QRaKCFaNmAbyw19YeeF/UU3gFL3W4fKX6kOlZrJU6ig pAfQ== X-Gm-Message-State: AOAM531kL7xIy2FAfgT1s5B6rG5kZxKnMOBpd1uvNeqge3LkCpJXlbid 0qpJtLpJWTQG+GWNBUCp240= X-Google-Smtp-Source: ABdhPJxvvYMVFDJX2kogk8wVpUB7/fRCYJGxwBsNk3d+WOOaAGnH2jU2iesJ6nuPX7+Aa9wgxh5ByA== X-Received: by 2002:a0c:f7cc:: with SMTP id f12mr45289qvo.0.1606942739121; Wed, 02 Dec 2020 12:58:59 -0800 (PST) Received: from ?IPv6:2620:10d:c0a8:1102:fd8c:7733:5cca:4143? ([2620:10d:c091:480::1:6627]) by smtp.googlemail.com with ESMTPSA id s11sm2907688qkm.124.2020.12.02.12.58.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Dec 2020 12:58:58 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: c++: typename_type structural comparison Message-ID: Date: Wed, 2 Dec 2020 15:58:57 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" For modules we need to compare structurally all the way down. This means inhibiting typename_type resolution, independent of comparing specializations. gcc/cp/ * cp-tree.h (comparing_typenames): Declare. * pt.c (comparing_typenames): Define. (spec_hasher::equal): Increment it around comparisons. * typeck.c (structural_comptypes): Adjust TYPENAME resolution check. pushing to trunk nathan diff --git i/gcc/cp/cp-tree.h w/gcc/cp/cp-tree.h index 3b67e7ae76a..f7a737910b6 100644 --- i/gcc/cp/cp-tree.h +++ w/gcc/cp/cp-tree.h @@ -5399,6 +5399,10 @@ extern int function_depth; in structrual_comptypes. */ extern int comparing_specializations; +/* Nonzero if we are inside eq_specializations, which affects + resolving of typenames in structural_comptypes. */ +extern int comparing_typenames; + /* In parser.c. */ /* Nonzero if we are parsing an unevaluated operand: an operand to diff --git i/gcc/cp/pt.c w/gcc/cp/pt.c index 4fb0bc82c31..19a2ea0acd4 100644 --- i/gcc/cp/pt.c +++ w/gcc/cp/pt.c @@ -1702,9 +1702,11 @@ register_specialization (tree spec, tree tmpl, tree args, bool is_friend, return spec; } -/* Returns true iff two spec_entry nodes are equivalent. */ - +/* Restricts tree and type comparisons. */ int comparing_specializations; +int comparing_typenames; + +/* Returns true iff two spec_entry nodes are equivalent. */ bool spec_hasher::equal (spec_entry *e1, spec_entry *e2) @@ -1712,6 +1714,7 @@ spec_hasher::equal (spec_entry *e1, spec_entry *e2) int equal; ++comparing_specializations; + ++comparing_typenames; equal = (e1->tmpl == e2->tmpl && comp_template_args (e1->args, e2->args)); if (equal && flag_concepts @@ -1727,6 +1730,7 @@ spec_hasher::equal (spec_entry *e1, spec_entry *e2) equal = equivalent_constraints (c1, c2); } --comparing_specializations; + --comparing_typenames; return equal; } diff --git i/gcc/cp/typeck.c w/gcc/cp/typeck.c index 267b284ea40..6294a787b5a 100644 --- i/gcc/cp/typeck.c +++ w/gcc/cp/typeck.c @@ -1256,16 +1256,15 @@ structural_comptypes (tree t1, tree t2, int strict) gcc_assert (TYPE_P (t1) && TYPE_P (t2)); - if (!comparing_specializations) - { - /* TYPENAME_TYPEs should be resolved if the qualifying scope is the - current instantiation. */ - if (TREE_CODE (t1) == TYPENAME_TYPE) - t1 = resolve_typename_type (t1, /*only_current_p=*/true); - - if (TREE_CODE (t2) == TYPENAME_TYPE) - t2 = resolve_typename_type (t2, /*only_current_p=*/true); - } + /* TYPENAME_TYPEs should be resolved if the qualifying scope is the + current instantiation, and we don't care about typename + structural equality. The comparing_typenames check is after the + code check, in order to early-out the common case. */ + if (TREE_CODE (t1) == TYPENAME_TYPE && !comparing_typenames) + t1 = resolve_typename_type (t1, /*only_current_p=*/true); + + if (TREE_CODE (t2) == TYPENAME_TYPE && !comparing_typenames) + t2 = resolve_typename_type (t2, /*only_current_p=*/true); if (TYPE_PTRMEMFUNC_P (t1)) t1 = TYPE_PTRMEMFUNC_FN_TYPE (t1);