From patchwork Sat Jul 13 23:02:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 258870 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 87F142C0157 for ; Sun, 14 Jul 2013 09:02:44 +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 :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=GJDIdFKP0X8rRfP/CYkaaBmFuQMaG5HFFGBzFW/OkBj 7uVgwWNsN3SRWA4HTYwCDq9F98N97maXLHjpm72y3/Sj6QzkLyWo/sN5QYsbPvR6 pdl5PSxEEJY488Ww9G46/54sOmE+G5+mq4ax2/zZUQmG099vTfiNZ+F2zWs1eDI4 = 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 :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=sc8kXtivfwSs93FqS6OwB7/S8OI=; b=T/a6E5+2Ypvkz4la1 vra20jlndvSc+z7quPQ9Rbf2+uOy4G4DtH0BCp+rl9/9jrel1UmGv5mTBFpJSeD4 u1bt1yV5dQX4WlFSli5c9G/GIWV9BimQ4Bf92Ai+YfsAmswfE/izRe9J5iuxyatC fDmvSKKvE1B3F8qUrCG1FnfGZo= Received: (qmail 8311 invoked by alias); 13 Jul 2013 23:02:38 -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 8301 invoked by uid 89); 13 Jul 2013 23:02:37 -0000 X-Spam-SWARE-Status: No, score=-5.0 required=5.0 tests=AWL, BAYES_40, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL, RDNS_NONE, SPF_HELO_PASS, SPF_PASS autolearn=no version=3.3.1 Received: from Unknown (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Sat, 13 Jul 2013 23:02:37 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r6DN2TJI019818 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 13 Jul 2013 19:02:29 -0400 Received: from [10.3.113.16] ([10.3.113.16]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r6DN2Sdr019604; Sat, 13 Jul 2013 19:02:29 -0400 Message-ID: <51E1DC84.20306@redhat.com> Date: Sat, 13 Jul 2013 16:02:28 -0700 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.0a2 MIME-Version: 1.0 To: gcc-patches List CC: Andrew Sutton Subject: C++ PATCH to can_convert to support user-defined conversions X-Virus-Found: No As came up in the review of the concepts lite code, can_convert currently doesn't allow user-defined conversions. This is surprising, so we've renamed it to can_convert_standard and made the can_convert name allow them. Users that could potentially call can_convert with arguments of class type have also been renamed; those that can only pass in pointers or the like have been left alone. I also took the opportunity to tidy up a covariant return diagnostic. Tested x86_64-pc-linux-gnu, applying to trunk. commit 17f84bee70fb11ac0a34d50584cfcfb5035b5360 Author: Jason Merrill Date: Thu Jul 4 09:12:04 2013 -0700 * call.c (can_convert): Allow user-defined conversions. (can_convert_standard): New. * cp-tree.h: Declare it. * cvt.c (convert_to_reference): Use it. * pt.c (convert_nontype_argument): Likewise. * search.c (check_final_overrider): Likewise. Don't worry about user-defined conversions. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 78899ab..02daf82 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -8814,6 +8814,20 @@ tourney (struct z_candidate *candidates, tsubst_flags_t complain) bool can_convert (tree to, tree from, tsubst_flags_t complain) { + tree arg = NULL_TREE; + /* implicit_conversion only considers user-defined conversions + if it has an expression for the call argument list. */ + if (CLASS_TYPE_P (from) || CLASS_TYPE_P (to)) + arg = build1 (CAST_EXPR, from, NULL_TREE); + return can_convert_arg (to, from, arg, LOOKUP_IMPLICIT, complain); +} + +/* Returns nonzero if things of type FROM can be converted to TO with a + standard conversion. */ + +bool +can_convert_standard (tree to, tree from, tsubst_flags_t complain) +{ return can_convert_arg (to, from, NULL_TREE, LOOKUP_IMPLICIT, complain); } diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 1971bc5..a837d22 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -5007,6 +5007,7 @@ extern tree build_op_delete_call (enum tree_code, tree, tree, bool, tree, tree, tsubst_flags_t); extern bool can_convert (tree, tree, tsubst_flags_t); +extern bool can_convert_standard (tree, tree, tsubst_flags_t); extern bool can_convert_arg (tree, tree, tree, int, tsubst_flags_t); extern bool can_convert_arg_bad (tree, tree, tree, int, diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index d9e905e..532e8fd 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -428,7 +428,7 @@ convert_to_reference (tree reftype, tree expr, int convtype, intype = TYPE_MAIN_VARIANT (intype); - can_convert_intype_to_type = can_convert (type, intype, complain); + can_convert_intype_to_type = can_convert_standard (type, intype, complain); if (!can_convert_intype_to_type && (convtype & CONV_IMPLICIT) && MAYBE_CLASS_TYPE_P (intype) @@ -449,7 +449,8 @@ convert_to_reference (tree reftype, tree expr, int convtype, } } - if (((convtype & CONV_STATIC) && can_convert (intype, type, complain)) + if (((convtype & CONV_STATIC) + && can_convert_standard (intype, type, complain)) || ((convtype & CONV_IMPLICIT) && can_convert_intype_to_type)) { { diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 877d3b7..de054ac 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -5854,7 +5854,7 @@ convert_nontype_argument (tree type, tree expr, tsubst_flags_t complain) "because it is of type %qT", expr, type, TREE_TYPE (expr)); /* If we are just one standard conversion off, explain. */ - if (can_convert (type, TREE_TYPE (expr), complain)) + if (can_convert_standard (type, TREE_TYPE (expr), complain)) inform (input_location, "standard conversions are not allowed in this context"); return NULL_TREE; diff --git a/gcc/cp/search.c b/gcc/cp/search.c index b113477..166ac11 100644 --- a/gcc/cp/search.c +++ b/gcc/cp/search.c @@ -1889,22 +1889,16 @@ check_final_overrider (tree overrider, tree basefn) fail = 1; } } - else if (!pedantic - && can_convert (TREE_TYPE (base_type), TREE_TYPE (over_type), - tf_warning_or_error)) + else if (can_convert_standard (TREE_TYPE (base_type), + TREE_TYPE (over_type), + tf_warning_or_error)) /* GNU extension, allow trivial pointer conversions such as converting to void *, or qualification conversion. */ { - /* can_convert will permit user defined conversion from a - (reference to) class type. We must reject them. */ - if (CLASS_TYPE_P (non_reference (over_return))) - fail = 2; - else - { - warning (0, "deprecated covariant return type for %q+#D", - overrider); - warning (0, " overriding %q+#D", basefn); - } + if (pedwarn (DECL_SOURCE_LOCATION (overrider), 0, + "invalid covariant return type for %q#D", overrider)) + inform (DECL_SOURCE_LOCATION (basefn), + " overriding %q+#D", basefn); } else fail = 2;