From patchwork Sun Dec 27 17:02:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 561183 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 D313E140C8A for ; Mon, 28 Dec 2015 04:02:27 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Vhsz+hs1; 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:from :to:cc:subject:date:message-id; q=dns; s=default; b=xE9bzqsSOXed W1HoOJFZK3zmOxbE3EUg3cPlU0f9eZEvPdtzcyPLLK0WIdC/zov9ks6Bsoq6bTqW CcZO+JaAR7jsBu/a/nBQi0tcNmmE2XUvl/Z8ks2tKWDs8HteHiSteFTj83s3hfN3 GTq93n9LxxPwjFsRoJnm47EE73UQdUI= 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:cc:subject:date:message-id; s=default; bh=eDWWRAMqvIlrJSk9zl Btj6pbSzo=; b=Vhsz+hs1GDgwa8SjKOjvvrz+QFp3QzsnuaYF2x2pMjD0hhmjeV ghRO+MECI+2fQxBG9NkFs85e5hpYJx7fitacWwjLA8Ncjg/ThmWJrGH3UnSb7Zjp ifS1XpS7C7Lhowe8+3spoxon0tQO/RmgQm7rs+cvYV1rcP5qVcwFBhZ4g= Received: (qmail 14369 invoked by alias); 27 Dec 2015 17:02:18 -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 14353 invoked by uid 89); 27 Dec 2015 17:02:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=packs, permit, Boost, our X-HELO: mail-qg0-f44.google.com Received: from mail-qg0-f44.google.com (HELO mail-qg0-f44.google.com) (209.85.192.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sun, 27 Dec 2015 17:02:16 +0000 Received: by mail-qg0-f44.google.com with SMTP id b35so5126239qge.0 for ; Sun, 27 Dec 2015 09:02:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=KUE6DjsT8VaL7j+0cg4GDTmVx3hOHXm903s9myaN8yY=; b=JjR4q84y9hiW7/9Fi6hHHTSThHf3NWhk8BmxV48jGPKNL77kxO/D07BP/djz6jqx1i SDla8tQgtmPjcYGd4zCOIRqUG2BtULwsE3xZZ4nZravgQI3eSqv+A8feY9ELm4Vp74tE 5a32clC5qx/ofMtjM+DuC/9y62g4r/ngcb3MHX9wDOs4UJv4zPQez71ydQS97H4565JZ N60hWqMB8U9cm53ao1cHD/wrUSarotPQ/ZMR/0YGCN3ca1CpkwSZTMERsitEoneJBIXC 7XCseHbFLT1jBiaUF575Y4jXpi5y1/xOUG5HAKQ5I69qjZsCwGQxNLI5GgIAv+RHaz8B O2VA== X-Gm-Message-State: ALoCoQnBn3qKcfOoVG0+07Y41ORqn0vtuwlh6BvlJ65VGlxgUiun7dFI76lckYb1XGVY43hshnMRFO29Dc6DSazznMaNOQdZng== X-Received: by 10.140.23.81 with SMTP id 75mr10396205qgo.35.1451235734308; Sun, 27 Dec 2015 09:02:14 -0800 (PST) Received: from localhost.localdomain (ool-4353a8be.dyn.optonline.net. [67.83.168.190]) by smtp.gmail.com with ESMTPSA id 138sm25625197qhi.37.2015.12.27.09.02.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 27 Dec 2015 09:02:13 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] Fix PR c++/69052 (argument pack deduction failure during overload resolution) Date: Sun, 27 Dec 2015 12:02:04 -0500 Message-Id: <1451235724-17299-1-git-send-email-patrick@parcs.ath.cx> In try_one_overload(), it should not be a deduction failure if we deduced more arguments of an argument pack than were explicitly specified (as long as the arguments are otherwise equivalent). This patch makes try_one_overload() manually check the argument packs, to permit such a case. Bootstrap + regtest in progress on x86_64-pc-linux-gnu, will also test against Boost. Is this OK to commit if testing succeeds? gcc/cp/ChangeLog: PR c++/69052 * pt.c (try_one_overload): Handle comparing argument packs so that there is no conflict if we deduced more arguments of an argument pack than were explicitly specified. gcc/testsuite/ChangeLog: PR c++/69052 g++.dg/cpp0x/pr69056.C: New test. --- gcc/cp/pt.c | 21 +++++++++++++++++++++ gcc/testsuite/g++.dg/cpp0x/pr69056.C | 30 ++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/pr69056.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index ff16b7c..cdbfadd 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -18694,6 +18694,27 @@ try_one_overload (tree tparms, template args used in the function parm list with our own template parms. Discard them. */ TREE_VEC_ELT (tempargs, i) = NULL_TREE; + else if (oldelt && ARGUMENT_PACK_P (oldelt)) + { + /* Check that the deduced argument at each index is equivalent to the + corresponding explicit argument. We may have deduced more + arguments than were explicitly specified, and that's OK. */ + gcc_assert (ARGUMENT_PACK_INCOMPLETE_P (oldelt)); + gcc_assert (ARGUMENT_PACK_ARGS (oldelt) + == ARGUMENT_PACK_EXPLICIT_ARGS (oldelt)); + + tree explicit_pack = ARGUMENT_PACK_ARGS (oldelt); + tree deduced_pack = ARGUMENT_PACK_ARGS (elt); + + if (TREE_VEC_LENGTH (deduced_pack) + < TREE_VEC_LENGTH (explicit_pack)) + return 0; + + for (int j = 0; j < TREE_VEC_LENGTH (explicit_pack); j++) + if (!template_args_equal (TREE_VEC_ELT (explicit_pack, j), + TREE_VEC_ELT (deduced_pack, j))) + return 0; + } else if (oldelt && !template_args_equal (oldelt, elt)) return 0; } diff --git a/gcc/testsuite/g++.dg/cpp0x/pr69056.C b/gcc/testsuite/g++.dg/cpp0x/pr69056.C new file mode 100644 index 0000000..ab4e071 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/pr69056.C @@ -0,0 +1,30 @@ +// { dg-do compile { target c++11 } } +// PR c++/69056 + +template +void resolver(int (*) (T, Args...)); + +int funcA(int, float) { return 0; } +int funcA(double) { return 0; } + +int funcB(int, float, char) { return 0; } +int funcB(int, bool) { return 0; } +int funcB(double) { return 0; } + +int funcC(int) { return 0; } +int funcC(double) { return 0; } + +void +foo (void) +{ + resolver (&funcA); // { dg-error "no match" } + resolver (&funcA); + resolver (&funcA); + + resolver (&funcB); // { dg-error "no match" } + resolver (&funcB); // { dg-error "no match" } + resolver (&funcB); + + resolver (&funcC); + resolver (&funcC); // { dg-error "no match" } +}