From patchwork Wed Jun 26 21:56:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 254880 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 221502C007C for ; Thu, 27 Jun 2013 07:56:34 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=ILXSEB5WkQGspF2Wja1b8u6nQm1pozPq0Df5+2gSDtufmPhkdF Orz2+uCZmNzZ8Rz+7dHwobVz3OjHWP2EnQK8AYrQ79/ghpvs1dY/M0yn0a8tKSYa pdfwO9ZAFH9hascNTePEF7tJPtYrN3DF+lM7YnJWG58lvB7wX3bJ857j8= 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:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=x5VRidjuevRvTEuSLbsklMMYgI8=; b=FwJlokjOW9/hVS532YDq 3dP3C6vZiTGHq3cpPn1CUNa73cLvbSTcILapWTonO4jwb1zpfxyB+rW3BrcmKget 4/0t1jm3wW9YvAMXJmE5jj65M+kcomXMnhe142m4EcstXMF2Ud/sIuDqMhp/BWO0 l/4P/poYLEG7guPiAL8wwPo= Received: (qmail 13020 invoked by alias); 26 Jun 2013 21:56:29 -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 13009 invoked by uid 89); 26 Jun 2013 21:56:28 -0000 X-Spam-SWARE-Status: No, score=-6.8 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RP_MATCHES_RCVD autolearn=ham version=3.3.1 Received: from mail2-relais-roc.national.inria.fr (HELO mail2-relais-roc.national.inria.fr) (192.134.164.83) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 26 Jun 2013 21:56:27 +0000 Received: from stedding.saclay.inria.fr ([193.55.250.194]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 26 Jun 2013 23:56:24 +0200 Received: from glisse (helo=localhost) by stedding.saclay.inria.fr with local-esmtp (Exim 4.80) (envelope-from ) id 1UrxhQ-00027X-Lx; Wed, 26 Jun 2013 23:56:24 +0200 Date: Wed, 26 Jun 2013 23:56:24 +0200 (CEST) From: Marc Glisse To: gcc-patches@gcc.gnu.org cc: jason@redhat.com Subject: [C++] Implement DR1164 Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 X-Virus-Found: No Hello, this patch tries to implement DR1164. It passes bootstrap+testsuite on x86_64-unknown-linux-gnu. 2013-06-27 Marc Glisse PR c++/57172 gcc/cp/ * pt.c (more_specialized_fn): If both arguments are references, give priority to an lvalue. gcc/testsuite/ * g++.dg/cpp0x/pr57172.C: New testcase. Index: gcc/testsuite/g++.dg/cpp0x/pr57172.C =================================================================== --- gcc/testsuite/g++.dg/cpp0x/pr57172.C (revision 0) +++ gcc/testsuite/g++.dg/cpp0x/pr57172.C (revision 0) @@ -0,0 +1,7 @@ +// PR c++/57172 +// { dg-do compile { target c++11 } } + +template int f (T&) { } +template int f (T&&) = delete; +int i; +int j = f (i); Property changes on: gcc/testsuite/g++.dg/cpp0x/pr57172.C ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision URL Added: svn:eol-style + native Index: gcc/cp/pt.c =================================================================== --- gcc/cp/pt.c (revision 200430) +++ gcc/cp/pt.c (working copy) @@ -17503,21 +17503,22 @@ check_undeduced_parms (tree targs, tree The 1998 std underspecified function template partial ordering, and DR214 addresses the issue. We take pairs of arguments, one from each of the templates, and deduce them against each other. One of the templates will be more specialized if all the *other* template's arguments deduce against its arguments and at least one of its arguments *does* *not* deduce against the other template's corresponding argument. Deduction is done as for class templates. The arguments used in deduction have reference and top level cv qualifiers removed. Iff both arguments were originally reference - types *and* deduction succeeds in both directions, the template + types *and* deduction succeeds in both directions, an lvalue reference + wins against an rvalue reference and otherwise the template with the more cv-qualified argument wins for that pairing (if neither is more cv-qualified, they both are equal). Unlike regular deduction, after all the arguments have been deduced in this way, we do *not* verify the deduced template argument values can be substituted into non-deduced contexts. The logic can be a bit confusing here, because we look at deduce1 and targs1 to see if pat2 is at least as specialized, and vice versa; if we can find template arguments for pat1 to make arg1 look like arg2, that means that arg2 is at least as specialized as arg1. */ @@ -17579,41 +17580,45 @@ more_specialized_fn (tree pat1, tree pat while (len-- /* Stop when an ellipsis is seen. */ && args1 != NULL_TREE && args2 != NULL_TREE) { tree arg1 = TREE_VALUE (args1); tree arg2 = TREE_VALUE (args2); int deduce1, deduce2; int quals1 = -1; int quals2 = -1; + int ref1 = 0; + int ref2 = 0; if (TREE_CODE (arg1) == TYPE_PACK_EXPANSION && TREE_CODE (arg2) == TYPE_PACK_EXPANSION) { /* When both arguments are pack expansions, we need only unify the patterns themselves. */ arg1 = PACK_EXPANSION_PATTERN (arg1); arg2 = PACK_EXPANSION_PATTERN (arg2); /* This is the last comparison we need to do. */ len = 0; } if (TREE_CODE (arg1) == REFERENCE_TYPE) { + ref1 = TYPE_REF_IS_RVALUE (arg1) + 1; arg1 = TREE_TYPE (arg1); quals1 = cp_type_quals (arg1); } if (TREE_CODE (arg2) == REFERENCE_TYPE) { + ref2 = TYPE_REF_IS_RVALUE (arg2) + 1; arg2 = TREE_TYPE (arg2); quals2 = cp_type_quals (arg2); } arg1 = TYPE_MAIN_VARIANT (arg1); arg2 = TYPE_MAIN_VARIANT (arg2); if (TREE_CODE (arg1) == TYPE_PACK_EXPANSION) { int i, len2 = list_length (args2); @@ -17677,33 +17682,47 @@ more_specialized_fn (tree pat1, tree pat /* If we couldn't deduce arguments for tparms1 to make arg1 match arg2, then arg2 is not as specialized as arg1. */ if (!deduce1) lose2 = true; if (!deduce2) lose1 = true; /* "If, for a given type, deduction succeeds in both directions (i.e., the types are identical after the transformations above) - and if the type from the argument template is more cv-qualified - than the type from the parameter template (as described above) - that type is considered to be more specialized than the other. If - neither type is more cv-qualified than the other then neither type - is more specialized than the other." */ + and both P and A were reference types (before being replaced with + the type referred to above): + - if the type from the argument template was an lvalue reference and + the type from the parameter template was not, the argument type is + considered to be more specialized than the other; otherwise, + - if the type from the argument template is more cv-qualified + than the type from the parameter template (as described above), + the argument type is considered to be more specialized than the other; + otherwise, + - neither type is more specialized than the other." */ - if (deduce1 && deduce2 - && quals1 != quals2 && quals1 >= 0 && quals2 >= 0) + if (deduce1 && deduce2) { - if ((quals1 & quals2) == quals2) - lose2 = true; - if ((quals1 & quals2) == quals1) - lose1 = true; + if (ref1 && ref2 && ref1 != ref2) + { + if (ref1 > ref2) + lose1 = true; + else + lose2 = true; + } + else if (quals1 != quals2 && quals1 >= 0 && quals2 >= 0) + { + if ((quals1 & quals2) == quals2) + lose2 = true; + if ((quals1 & quals2) == quals1) + lose1 = true; + } } if (lose1 && lose2) /* We've failed to deduce something in either direction. These must be unordered. */ break; if (TREE_CODE (arg1) == TYPE_PACK_EXPANSION || TREE_CODE (arg2) == TYPE_PACK_EXPANSION) /* We have already processed all of the arguments in our