From patchwork Tue Jun 15 20:04:56 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 55789 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]) by ozlabs.org (Postfix) with SMTP id 486DA1007D3 for ; Wed, 16 Jun 2010 06:05:13 +1000 (EST) Received: (qmail 6033 invoked by alias); 15 Jun 2010 20:05:10 -0000 Received: (qmail 6019 invoked by uid 22791); 15 Jun 2010 20:05:08 -0000 X-SWARE-Spam-Status: No, hits=-5.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_NV, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 15 Jun 2010 20:05:00 +0000 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5FK4wNU008616 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 15 Jun 2010 16:04:58 -0400 Received: from [IPv6:::1] (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5FK4u7H025205 for ; Tue, 15 Jun 2010 16:04:57 -0400 Message-ID: <4C17DCE8.7080002@redhat.com> Date: Tue, 15 Jun 2010 16:04:56 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.10) Gecko/20100603 Lightning/1.0b1 Shredder/3.0.6pre MIME-Version: 1.0 To: gcc-patches List Subject: minor C++ PATCH to improve ambiguous conversion diagnostics 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 I noticed we weren't giving the "initializing parameter N of foo(bar)" message for ambiguous conversions that we give for other conversion errors. I also moved that message to the site of the function declaration, since we already have a message at the call site. Tested x86_64-pc-linux-gnu, applying to trunk. commit 02b8944317de822b7d231fd4d3ec7f0d367821c8 Author: Jason Merrill Date: Mon Jun 14 10:08:22 2010 -0400 * call.c (convert_like_real): Give "initializing argument of" information for ambiguous conversion. Give source position of function. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index a735dc6..55089ed 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -4934,7 +4934,8 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, { permerror (input_location, "invalid conversion from %qT to %qT", TREE_TYPE (expr), totype); if (fn) - permerror (input_location, " initializing argument %P of %qD", argnum, fn); + permerror (DECL_SOURCE_LOCATION (fn), + " initializing argument %P of %qD", argnum, fn); } else return error_mark_node; @@ -5018,11 +5019,14 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, } return expr; case ck_ambig: - if (!(complain & tf_error)) - return error_mark_node; - /* Call build_user_type_conversion again for the error. */ - return build_user_type_conversion - (totype, convs->u.expr, LOOKUP_NORMAL); + if (complain & tf_error) + { + /* Call build_user_type_conversion again for the error. */ + build_user_type_conversion (totype, convs->u.expr, LOOKUP_NORMAL); + if (fn) + error (" initializing argument %P of %q+D", argnum, fn); + } + return error_mark_node; case ck_list: { @@ -5110,7 +5114,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, if (diag_kind && fn) { if ((complain & tf_error)) - emit_diagnostic (diag_kind, input_location, 0, + emit_diagnostic (diag_kind, DECL_SOURCE_LOCATION (fn), 0, " initializing argument %P of %qD", argnum, fn); else if (diag_kind == DK_ERROR) return error_mark_node; diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist15.C b/gcc/testsuite/g++.dg/cpp0x/initlist15.C index d59e5af..b75cc81 100644 --- a/gcc/testsuite/g++.dg/cpp0x/initlist15.C +++ b/gcc/testsuite/g++.dg/cpp0x/initlist15.C @@ -1,5 +1,8 @@ // { dg-options "-std=c++0x" } +// Just discard errors pointing at header files +// { dg-prune-output "include" } + #include #include diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist19.C b/gcc/testsuite/g++.dg/cpp0x/initlist19.C index 418cddc..9cb197c 100644 --- a/gcc/testsuite/g++.dg/cpp0x/initlist19.C +++ b/gcc/testsuite/g++.dg/cpp0x/initlist19.C @@ -1,8 +1,10 @@ // { dg-options "-std=c++0x" } +// Allow other errors, too +// { dg-prune-output "error" } + void f(double); int main() { f({{1}}); // { dg-error "too many braces" } - // { dg-error "" "" { target *-*-* } 6 } allow other errors, too } diff --git a/gcc/testsuite/g++.dg/expr/cond8.C b/gcc/testsuite/g++.dg/expr/cond8.C index f05c81a..11708ec 100644 --- a/gcc/testsuite/g++.dg/expr/cond8.C +++ b/gcc/testsuite/g++.dg/expr/cond8.C @@ -3,11 +3,11 @@ struct A { - A(void*); + A(void*); // { dg-error "initializing" } ~A(); }; void foo(const int i, bool b) { - b ? A(0) : i; // { dg-error "conversion|initializing" } + b ? A(0) : i; // { dg-error "conversion" } } diff --git a/gcc/testsuite/g++.old-deja/g++.bugs/900514_03.C b/gcc/testsuite/g++.old-deja/g++.bugs/900514_03.C index 3826e08..c06cef1 100644 --- a/gcc/testsuite/g++.old-deja/g++.bugs/900514_03.C +++ b/gcc/testsuite/g++.old-deja/g++.bugs/900514_03.C @@ -16,7 +16,7 @@ struct t_0_st_0; -struct t_0_st_1 { +struct t_0_st_1 { // { dg-error "initializing" } int member; t_0_st_1 (t_0_st_0&);// { dg-message "note" } @@ -83,7 +83,7 @@ void t_1_local_init () struct t_2_st_0; -struct t_2_st_1 { +struct t_2_st_1 { // { dg-error "initializing" } int member; t_2_st_1 (t_2_st_0); // { dg-message "note" } diff --git a/libstdc++-v3/testsuite/ext/ext_pointer/1_neg.cc b/libstdc++-v3/testsuite/ext/ext_pointer/1_neg.cc index bab32fa..c599aca 100644 --- a/libstdc++-v3/testsuite/ext/ext_pointer/1_neg.cc +++ b/libstdc++-v3/testsuite/ext/ext_pointer/1_neg.cc @@ -92,12 +92,7 @@ void test01(void) { } // { dg-error "invalid conversion " "" { target *-*-* } 314 } -// { dg-error "initializing argument 1 of" "" { target *-*-* } 314 } // { dg-error "invalid conversion " "" { target *-*-* } 308 } -// { dg-error "initializing argument 1 of" "" { target *-*-* } 308 } // { dg-error "invalid conversion " "" { target *-*-* } 331 } -// { dg-error "initializing argument 1 of" "" { target *-*-* } 331 } // { dg-error "invalid conversion " "" { target *-*-* } 339 } -// { dg-error "initializing argument 1 of" "" { target *-*-* } 339 } // { dg-excess-errors "In constructor" } -