From patchwork Mon May 29 14:13:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 768212 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 3wbzHg6ywsz9rxl for ; Tue, 30 May 2017 00:13:50 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="IA0TvkUS"; 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=PNBpTRZe9b4D90MGdOqZITz/NFj4vtHdKfGzlRBZMveUBHh6Ym m9cJhuYthG0iDFItXepvJGD4Qvj0NzUSpykg34+Y6DLYsN74F0Bv/57+5gRTK27m daf3ZqNC/Ucc+A3YQnJfxpewavi7mKpnADni8R6v0T8DxQR9XJyHviCfg= 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=2SLghIA1C7QJNiGmZwt/GAFkg1c=; b=IA0TvkUSy1qA9bw7ddOC cnj3lP1PKIz9zKn81V8zPbYztpQuK2JN15eMmXiU+dL8+ZVq6pHGqxP3Zl7vgeNU xtVAwzE5eN0J3wfbrH6xTaIfi84Xkp/JjQ3NX6AmcSP4dw2fSFBMqhGopaqNMNsk GUSPpx89O9jU1uvVlRJiXos= Received: (qmail 31005 invoked by alias); 29 May 2017 14:13:36 -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 30957 invoked by uid 89); 29 May 2017 14:13:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS, SUBJ_ALL_CAPS autolearn=ham version=3.3.2 spammy=equally X-HELO: mail-yb0-f169.google.com Received: from mail-yb0-f169.google.com (HELO mail-yb0-f169.google.com) (209.85.213.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 29 May 2017 14:13:33 +0000 Received: by mail-yb0-f169.google.com with SMTP id r66so8457771yba.2 for ; Mon, 29 May 2017 07:13:37 -0700 (PDT) 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=+SxptB4q59Rxo+z/FMQp5TvpDEJL8eEhIz61HMCIEWU=; b=sKyYGEIqHxpQjWS0/ZLxp9mSPQbvM9eXVlijMjq7it97cWkr9lsH/MB91eGry6j9WA u4eXlsnk2OKNalGpMCo2oAx9PDEPokRDWvV9UVKXYci46JqRZyfmGuFE7AZY4Rn7H54c nNZIaCvOXUg7Rcb6x+LP6/BnBD8JXgIbFH8N4oaXp008pG9/jpJSu3HRMcabhsGlJalm bzI/zr2spgoVYx2VkGLVWmk5W4oOe46sPIbSEwfek1LXoxPlSwgnoXmKM7xbX64oAaIB Wfn9iwLjN1Qi78b0UE1IYNoVIrAhPJqqkmeeAbIgvOpDR3IPlqXgQlg9aCGKDLPLkOj/ wXvg== X-Gm-Message-State: AODbwcCWb3wUSTQXxPBHgonbQUeAhWiPxi7AwVDphKwUBdPe5UEf3neD vbD3o4EpLGrv6g== X-Received: by 10.37.172.19 with SMTP id w19mr29309793ybi.14.1496067215497; Mon, 29 May 2017 07:13:35 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a1:1102:b9b0:1beb:d21c:b3f4? ([2620:10d:c091:180::d0e1]) by smtp.googlemail.com with ESMTPSA id q20sm4833584ywa.70.2017.05.29.07.13.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 May 2017 07:13:34 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] PR 80891 #1 Message-ID: <454b3711-2d2f-2343-c69e-2b20db357855@acm.org> Date: Mon, 29 May 2017 10:13:33 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 This patch fixes the first testcase in 80891. That was a case af a using declaration and a using directive bringing in the same function during lookup. the template specialization machinery wasn't prepared for that, and reasonably thought neither instance was more specialized. This patch teaches most_specialized_template to ignore duplicates. However, I think my decision to permit lookup to return duplicates was wrong. It should try harder not to -- as (a) it appears to be more common than I'd guessed and (b) the cost of returning duplicates is high, as both go through the instantiation machinery when there are templates involved. Now that using declarations are ordered wrt regular functions, we can do better than before -- and even if we couldn't we can do no worse. I've committed this patch, to unbreak things, but I'm going to leave the defect open and fixup lookup shortly, along with turning this patch into an appropriate assert. nathan 2017-05-29 Nathan Sidwell PR c++/80891 (#1) * pt.c (most_specialized_instantiation): Cope with duplicate instantiations. PR c++/80891 (#1) * g++.dg/lookup/pr80891-1.C: New. Index: cp/pt.c =================================================================== --- cp/pt.c (revision 248571) +++ cp/pt.c (working copy) @@ -21728,31 +21728,32 @@ most_specialized_instantiation (tree tem champ = templates; for (fn = TREE_CHAIN (templates); fn; fn = TREE_CHAIN (fn)) - { - int fate = more_specialized_inst (TREE_VALUE (champ), TREE_VALUE (fn)); - if (fate == -1) - champ = fn; - else if (!fate) - { - /* Equally specialized, move to next function. If there - is no next function, nothing's most specialized. */ - fn = TREE_CHAIN (fn); + if (TREE_VALUE (champ) != TREE_VALUE (fn)) + { + int fate = more_specialized_inst (TREE_VALUE (champ), TREE_VALUE (fn)); + if (fate == -1) champ = fn; - if (!fn) - break; - } - } + else if (!fate) + { + /* Equally specialized, move to next function. If there + is no next function, nothing's most specialized. */ + fn = TREE_CHAIN (fn); + champ = fn; + if (!fn) + break; + } + } if (champ) /* Now verify that champ is better than everything earlier in the instantiation list. */ - for (fn = templates; fn != champ; fn = TREE_CHAIN (fn)) { - if (more_specialized_inst (TREE_VALUE (champ), TREE_VALUE (fn)) != 1) - { - champ = NULL_TREE; - break; - } - } + for (fn = templates; fn != champ; fn = TREE_CHAIN (fn)) + if (TREE_VALUE (champ) != TREE_VALUE (fn) + && more_specialized_inst (TREE_VALUE (champ), TREE_VALUE (fn)) != 1) + { + champ = NULL_TREE; + break; + } processing_template_decl--; Index: testsuite/g++.dg/lookup/pr80891-1.C =================================================================== --- testsuite/g++.dg/lookup/pr80891-1.C (revision 0) +++ testsuite/g++.dg/lookup/pr80891-1.C (working copy) @@ -0,0 +1,19 @@ +// PR c++/80891 part 1 +// std::endl is found via two paths and most_specialized_instantiation +// gets confused. + +namespace std { + struct A { + void operator<<(A(A)); + }; + template _CharT endl(_Traits); + A a; +} + +using std::endl; + +void chi_squared_sample_sized() +{ + using namespace std; + a << endl; +}