From patchwork Wed Feb 12 20:05:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1237064 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-519431-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.a=rsa-sha1 header.s=default header.b=Mp0tN+wt; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TShEHQoR; 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 48HrHm1Yygz9s1x for ; Thu, 13 Feb 2020 07:06:10 +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:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=aKvrmXbIi7amxyHj AoHjYH+quy+nanjcZ9fqnHGN6NB5xDyN3xgKyESE6PWfzw7Gy8y7wF3bp1bDerNG 0eKfES/3ntAWxv1iksocgLCazn3hFd15T+rbZ+hIbUd3V361RxNFSZP/JAPb3IAP y9XHoUTwBdbGABoTHKT+MqqDV1w= 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:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=NpaHCKPvHVp90GilN/c1j+ QqXSY=; b=Mp0tN+wt4l+oOPb7kbZPJE08/9myyxjtowtzxsZ7zMg8gJzfZwi5oZ SmgaE1v53cIP1qXVXhjEwopeH/JIJv5aEAojUwp4Ij6vcAmMiYcm3P2nuBsZRcTk d6Bk3jmNs4JbPjafBFdjA2Jb0DviZ3ObO9lgvoanYxeCXCM+mQ+q8= Received: (qmail 72868 invoked by alias); 12 Feb 2020 20:06:03 -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 72855 invoked by uid 89); 12 Feb 2020 20:06:02 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE 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) (207.211.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 12 Feb 2020 20:06:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581537960; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VyowNifsim1pVSk7cRJpygGWneAnjtxHK1rdaeiuZBE=; b=TShEHQoRgJZQvAtw8RJfL5/rfNlT6TQ87AyiiS2OfGS/seao6boZ36Jn926o6GHVG8xqxy D8y23oaBfwo6KV+qxMOR3uQyHm0n2bJQLmySOqgwApqBtwL6NN6ZmcAN1x2ppkzaj8zqsP AS9TG1bXqfiHFFH+Q8OcwVPc4c868jk= 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-205-GprmtPHgMqCvZCBpbfV-NA-1; Wed, 12 Feb 2020 15:05:58 -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 446FF13E4 for ; Wed, 12 Feb 2020 20:05:57 +0000 (UTC) Received: from pdp-11.bss.redhat.com (unknown [10.20.4.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD16219C6A; Wed, 12 Feb 2020 20:05:56 +0000 (UTC) From: Marek Polacek To: GCC Patches , Jason Merrill Subject: [PATCH] c++: Fix poor diagnostic for array initializer [PR93710] Date: Wed, 12 Feb 2020 15:05:35 -0500 Message-Id: <20200212200535.459667-1-polacek@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com A small improvement for an error in build_user_type_conversion_1: instead of array-init1.C:11:1: error: conversion from ‘long int’ to ‘A’ is ambiguous 11 | }; | ^ we will print array-init1.C:8:3: error: conversion from ‘long int’ to ‘A’ is ambiguous 8 | 0L, | ^~ Bootstrapped/regtested on x86_64-linux, ok for trunk? 2020-02-12 Marek Polacek PR c++/93710 - poor diagnostic for array initializer. * call.c (build_user_type_conversion_1): Use cp_expr_loc_or_input_loc for an error call. * g++.dg/diagnostic/array-init1.C: New test. --- gcc/cp/call.c | 5 +++-- gcc/testsuite/g++.dg/diagnostic/array-init1.C | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/diagnostic/array-init1.C base-commit: 5bfc8303ffe2d86e938d45f13cd99a39469dac4f diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 51621b7dd87..f47f96bf1c2 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -4172,8 +4172,9 @@ build_user_type_conversion_1 (tree totype, tree expr, int flags, if (complain & tf_error) { auto_diagnostic_group d; - error ("conversion from %qH to %qI is ambiguous", - fromtype, totype); + error_at (cp_expr_loc_or_input_loc (expr), + "conversion from %qH to %qI is ambiguous", + fromtype, totype); print_z_candidates (location_of (expr), candidates); } diff --git a/gcc/testsuite/g++.dg/diagnostic/array-init1.C b/gcc/testsuite/g++.dg/diagnostic/array-init1.C new file mode 100644 index 00000000000..78580ad6b83 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/array-init1.C @@ -0,0 +1,11 @@ +// PR c++/93710 - poor diagnostic for array initializer. + +struct A { A (int); A (char*); int i; }; + +int x; + +A a1[] = { + 0L, // { dg-error "3:conversion from .long int. to .A. is ambiguous" } + &x, // { dg-error "3:invalid conversion from .int\\*. to .int." } + __builtin_offsetof (A, i) // { dg-error "23:conversion from .long unsigned int. to .A. is ambiguous" } +};