From patchwork Tue Nov 19 23:38:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1197689 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-514083-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="POATbFEn"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="Y71L0PYY"; 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 47Hj246W1Cz9sPL for ; Wed, 20 Nov 2019 10:38:34 +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:content-transfer-encoding; q=dns; s=default; b=DMU 8xTGdmSDHXeI468IEE//YcMg60zE6SeM4lQyu04ldkzsLBNriW5iklEvA0LsNaQH slXFKQVqRRfyKl9Ac9NWbZlCq9ywbLhwRC9CWvclZH/v9Zi5yThNFq8PNQ4rJ4aD nyI3UyEllL60TnutmVoJNNeXG9y7OgIvRMjD/Ii8= 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:content-transfer-encoding; s=default; bh=TU931T00c z2ikSzWO8JMYglsMOc=; b=POATbFEn4BwA/T188f9OqFRec3S467xQR/Fzz3yYf c9456uR87LpXaqBjBuH1ULCS+YqaluNeP+EKGQRd0ZKBCOIC9QGTwAfLMa/WnvsV 7Hpx2iw/DAlMClhsAs/IITu5kzGtDHeGgS86MpmdaL2SS32qw1IzEqtYEJHC+NSy 4I= Received: (qmail 95789 invoked by alias); 19 Nov 2019 23:38:26 -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 95780 invoked by uid 89); 19 Nov 2019 23:38:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-delivery-1.mimecast.com Received: from us-smtp-1.mimecast.com (HELO us-smtp-delivery-1.mimecast.com) (205.139.110.61) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 19 Nov 2019 23:38:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574206703; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8DowhgpOaoBDAhmPPjAKsq5M54JkckGkEjnPGtiD7T0=; b=Y71L0PYY9MK351aTQgwEWIP9X+GS2C8HBalGdHILoG0x0K9sJGwKlE4cutalfveax6QG8D 77KB+Tvr8PmNcWmEpQJy2lRZGZAaOKrFZ4IRxt5TFgZoWFIfCoR4uNeXK3jLeGlA1TBt4f eFdsvcH+2kRQiewTQir24CF9l7FwXM8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-204-x0ig5XPTOqiQQqdBisGxgg-1; Tue, 19 Nov 2019 18:38:19 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5D3111005500 for ; Tue, 19 Nov 2019 23:38:18 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-21.ams2.redhat.com [10.36.116.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E2C9952F3; Tue, 19 Nov 2019 23:38:17 +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 xAJNcFwh029768; Wed, 20 Nov 2019 00:38:16 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id xAJNcEM1029767; Wed, 20 Nov 2019 00:38:14 +0100 Date: Wed, 20 Nov 2019 00:38:14 +0100 From: Jakub Jelinek To: Jason Merrill , David Malcolm Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix weird addr_expr not supported by dump_expr messages (PR c++/90767) Message-ID: <20191119233814.GO4650@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Mimecast-Spam-Score: 0 Content-Disposition: inline X-IsSubscribed: yes Hi! The following patch is a minimal fix to avoid cannot convert ‘‘addr_expr’ not supported by dump_type’ to ‘X*’ and similar messages. The recently added complain_about_bad_argument function expects a from_type argument, but conv->from isn't necessarily a type, it can be an expression too. With this patch one gets error like: cannot convert ‘const X*’ to ‘X*’ and note like initializing argument 'this' of ‘void X::foo()’ Still, perhaps what GCC 8 and earlier used to emit might be clearer: pr90767-1.C: In member function ‘X::operator T() const’: pr90767-1.C:12:7: error: no matching function for call to ‘X::foo() const’ pr90767-1.C:6:8: note: candidate: ‘void X::foo()’ pr90767-1.C:6:8: note: passing ‘const X*’ as ‘this’ argument discards qualifiers There is the print_conversion_rejection function that handles the various cases, like this vs. other arguments, conv->from with expr type vs. type etc. Though, I must say I don't understand the reasons why complain_about_bad_argument has been added and whether we'd want to emit there what print_conversion_rejection prints as notes with 2 leading spaces instead as errors with no leading spaces. In any case, I think the patch below is a step in the right direction. 2019-11-19 Jakub Jelinek PR c++/90767 * call.c (complain_about_no_candidates_for_method_call): If conv->from is not a type, pass to complain_about_bad_argument lvalue_type of conv->from. * g++.dg/diagnostic/pr90767-1.C: New test. * g++.dg/diagnostic/pr90767-2.C: New test. Jakub --- gcc/cp/call.c.jj 2019-11-18 18:49:14.461880924 +0100 +++ gcc/cp/call.c 2019-11-19 14:40:19.121937148 +0100 @@ -9861,8 +9861,11 @@ complain_about_no_candidates_for_method_ if (const conversion_info *conv = maybe_get_bad_conversion_for_unmatched_call (candidate)) { + tree from_type = conv->from; + if (!TYPE_P (conv->from)) + from_type = lvalue_type (conv->from); complain_about_bad_argument (conv->loc, - conv->from, conv->to_type, + from_type, conv->to_type, candidate->fn, conv->n_arg); return; } --- gcc/testsuite/g++.dg/diagnostic/pr90767-1.C.jj 2019-11-19 14:48:00.386041586 +0100 +++ gcc/testsuite/g++.dg/diagnostic/pr90767-1.C 2019-11-19 14:46:53.395043036 +0100 @@ -0,0 +1,15 @@ +// PR c++/90767 +// { dg-do compile } + +struct X { + int n; + void foo (); // { dg-message "initializing argument 'this'" } + + template + operator T () const + { + if (n == 0) + foo (); // { dg-error "cannot convert 'const X\\*' to 'X\\*'" } + return n; + } +}; --- gcc/testsuite/g++.dg/diagnostic/pr90767-2.C.jj 2019-11-19 14:50:48.923522136 +0100 +++ gcc/testsuite/g++.dg/diagnostic/pr90767-2.C 2019-11-19 14:52:27.324051149 +0100 @@ -0,0 +1,15 @@ +// PR c++/90767 +// { dg-do compile } + +struct A { + struct B { B (int) {} }; + + template + void foo () + { + int x = 0; + bar (x); // { dg-error "cannot convert 'int' to 'A::B&'" } + } + + void bar (B &arg) {} // { dg-message "initializing argument 1" } +};