From patchwork Thu Jan 18 23:35:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 863224 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-471626-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="wwcChl6e"; dkim-atps=neutral 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 3zN0gq4thMz9t67 for ; Fri, 19 Jan 2018 10:35:35 +1100 (AEDT) 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:reply-to:mime-version :content-type; q=dns; s=default; b=jK6FROItVkkDcadYZIChwMPNxotzH IK5V4aAbGXtUVvO47lkQHNxgCUiWhxlZjoipHGKWnbhbaQJ5A9QTQAFureWkGUr8 wOb20vGtdV7S4eKcArCUsV2UcHQEh7B3hqVjA+Zi6UyVi0idHbbjG7j7dTzt6RyK 2jwjtqCC40QaXE= 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:reply-to:mime-version :content-type; s=default; bh=oOQWDaeVw7nS9HDkq6O5ru31IdI=; b=wwc Chl6euJmmeutmQyEf4atCPrVaWIQtktI1Oh2UqlmqQGAdGnSvLUALPgl7yXpqoIe TZ6zwJ0o9pmUwOW48Yzcde2PeSmbbslg5H7WfYelPopm4LHdOvHu5T0UWSgSH/k8 cF9fzJXqhBi2CSmPOkBi7vbzc1gPOdQAQ7DRvups= Received: (qmail 104307 invoked by alias); 18 Jan 2018 23:35:28 -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 104297 invoked by uid 89); 18 Jan 2018 23:35:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 18 Jan 2018 23:35:27 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1C07780464; Thu, 18 Jan 2018 23:35:26 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-22.ams2.redhat.com [10.36.117.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B83835D6B4; Thu, 18 Jan 2018 23:35:25 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w0INZMdv022249; Fri, 19 Jan 2018 00:35:23 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w0INZL6T022248; Fri, 19 Jan 2018 00:35:21 +0100 Date: Fri, 19 Jan 2018 00:35:21 +0100 From: Jakub Jelinek To: Jason Merrill , Nathan Sidwell , David Malcolm Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix ICE in joust with -Wconversion (PR c++/81167) Message-ID: <20180118233521.GP2063@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) X-IsSubscribed: yes Hi! As mentioned in the PR, we ICE on this testcase because w->fn is a conversion operator, w->convs[0]->type is a reference to a class type, but because that conversion is ck_ref_bind, source_type looks through it and finds ck_identity with the class type. Then we because w->fn is not a constructor do source = TREE_TYPE (source);, assuming we got a pointer type like on the other 5 testcases in check-c++-all with -Wconversion that cover this code, so source is NULL and we die in calling warning with bogus arguments. The following patch fixes it by only using TREE_TYPE on pointer/reference types. I must say I don't understand this fully, but conversion operators should be used on class types, so that is what we are looking for with source, right? No idea about the ! DECL_CONSTRUCTOR_P (w->fn) check though and nothing in the testsuite covers that. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-01-18 Jakub Jelinek PR c++/81167 * call.c (joust): Only use TREE_TYPE (source) if source is a POINTER_TYPE_P. * g++.dg/cpp0x/pr81167.C: New test. Jakub --- gcc/cp/call.c.jj 2018-01-17 22:00:13.626228171 +0100 +++ gcc/cp/call.c 2018-01-18 21:01:51.596136303 +0100 @@ -10082,7 +10082,7 @@ joust (struct z_candidate *cand1, struct else if (warn) { tree source = source_type (w->convs[0]); - if (! DECL_CONSTRUCTOR_P (w->fn)) + if (! DECL_CONSTRUCTOR_P (w->fn) && POINTER_TYPE_P (source)) source = TREE_TYPE (source); if (warning (OPT_Wconversion, "choosing %qD over %qD", w->fn, l->fn) && warning (OPT_Wconversion, " for conversion from %qH to %qI", --- gcc/testsuite/g++.dg/cpp0x/pr81167.C.jj 2018-01-18 21:07:48.723189500 +0100 +++ gcc/testsuite/g++.dg/cpp0x/pr81167.C 2018-01-18 21:07:18.610187374 +0100 @@ -0,0 +1,24 @@ +// PR c++/81167 +// { dg-do compile { target c++11 } } +// { dg-options "-Wconversion" } + +struct bar; + +struct foo +{ + foo () {} + foo (const bar &) {} +}; + +struct bar +{ + operator foo () && { return foo (); } +}; + +void test () +{ + foo f = bar (); +// { dg-warning "choosing 'bar::operator foo\\(\\) &&' over 'foo::foo\\(const bar&\\)'" "" { target *-*-* } .-1 } +// { dg-warning "for conversion from 'bar' to 'foo'" "" { target *-*-* } .-2 } +// { dg-message "because conversion sequence for the argument is better" "" { target *-*-* } .-3 } +}