From eef65c474e6836cc0470eb84f28895050161fcb8 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Wed, 12 Feb 2020 14:00:51 -0500 Subject: [PATCH] c++: Fix poor diagnostic for array initializer [PR93710] MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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, | ^~ 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/ChangeLog | 6 ++++++ gcc/cp/call.c | 5 +++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/diagnostic/array-init1.C | 11 +++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/diagnostic/array-init1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6ac938b4d2b..f6b5517d5e4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2020-02-15 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. + 2020-02-15 Jason Merrill PR c++/92556 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/ChangeLog b/gcc/testsuite/ChangeLog index dca5b150c08..7c198dcdc69 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-02-15 Marek Polacek + + PR c++/93710 - poor diagnostic for array initializer. + * g++.dg/diagnostic/array-init1.C: New test. + 2020-02-15 Jason Merrill * lib/target-supports.exp (check_effective_target_c++2a_only): Also 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" } +}; -- 2.30.2