From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1314) id 204C33857712; Sun, 30 Apr 2023 21:49:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 204C33857712 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682891371; bh=FQ/HNnYiEsatOLIz6mgY9HjfJ1cwDMYmHZXn9oRgQBs=; h=From:To:Subject:Date:From; b=wPsF4qeJV7AuX1Im1ztPbyUAocSJLvES0sZDbF9CGoBaZreaeF6Zpsc25skZrZ2Gg lJikellypJUwS5mRPlUVq+Hidthlo44vVVKJKG19PLgt5FEb35XF275SZ+Zx+gSsbG 1zv2nsjuQE3GsPAeXoREdEiT5tATxGIFYFrNIbDs= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Pinski To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-364] Improve error message for excess elements in array initializer from {"a"} X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/trunk X-Git-Oldrev: a6b810ae783acf8cec2d2272a46bd6de0976f496 X-Git-Newrev: d56af02fb1fd6eb50beb8a1689cf646bc567dbfc Message-Id: <20230430214931.204C33857712@sourceware.org> Date: Sun, 30 Apr 2023 21:49:31 +0000 (GMT) List-Id: https://gcc.gnu.org/g:d56af02fb1fd6eb50beb8a1689cf646bc567dbfc commit r14-364-gd56af02fb1fd6eb50beb8a1689cf646bc567dbfc Author: Andrew Pinski Date: Wed Nov 30 04:02:07 2022 +0000 Improve error message for excess elements in array initializer from {"a"} So char arrays are not the only type that be initialized from {"a"}. We can have wchar_t (L"") and char16_t (u"") types too. So let's print out the type of the array instead of just saying char. Note in the testsuite I used regex . to match '[' and ']' as I could not figure out how many '\' I needed. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/c/ChangeLog: * c-typeck.cc (process_init_element): Print out array type for excessive elements. gcc/testsuite/ChangeLog: * gcc.dg/init-bad-1.c: Update error message. * gcc.dg/init-bad-2.c: Likewise. * gcc.dg/init-bad-3.c: Likewise. * gcc.dg/init-excess-3.c: Likewise. * gcc.dg/pr61096-1.c: Likewise. Diff: --- gcc/c/c-typeck.cc | 2 +- gcc/testsuite/gcc.dg/init-bad-1.c | 2 +- gcc/testsuite/gcc.dg/init-bad-2.c | 2 +- gcc/testsuite/gcc.dg/init-bad-3.c | 2 +- gcc/testsuite/gcc.dg/init-excess-3.c | 12 ++++++------ gcc/testsuite/gcc.dg/pr61096-1.c | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index 9cc7e0143a9..f619e2a67e7 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -10647,7 +10647,7 @@ process_init_element (location_t loc, struct c_expr value, bool implicit, { if (constructor_stack->replacement_value.value) { - error_init (loc, "excess elements in % array initializer"); + error_init (loc, "excess elements in %qT initializer", constructor_type); return; } else if (string_flag) diff --git a/gcc/testsuite/gcc.dg/init-bad-1.c b/gcc/testsuite/gcc.dg/init-bad-1.c index 0da10c31539..7c80006670c 100644 --- a/gcc/testsuite/gcc.dg/init-bad-1.c +++ b/gcc/testsuite/gcc.dg/init-bad-1.c @@ -18,7 +18,7 @@ char s[1] = "x"; char s1[1] = { "x" }; char t[1] = "xy"; /* { dg-warning "initializer-string for array of 'char' is too long" } */ char t1[1] = { "xy" }; /* { dg-warning "initializer-string for array of 'char' is too long" } */ -char u[1] = { "x", "x" }; /* { dg-error "excess elements in 'char' array initializer" } */ +char u[1] = { "x", "x" }; /* { dg-error "excess elements in 'char.1.' initializer" } */ /* { dg-message "near init" "near" { target *-*-* } .-1 } */ int i = { }; diff --git a/gcc/testsuite/gcc.dg/init-bad-2.c b/gcc/testsuite/gcc.dg/init-bad-2.c index 4775c4807bb..57fd9f99f82 100644 --- a/gcc/testsuite/gcc.dg/init-bad-2.c +++ b/gcc/testsuite/gcc.dg/init-bad-2.c @@ -19,7 +19,7 @@ char s[1] = "x"; char s1[1] = { "x" }; char t[1] = "xy"; /* { dg-warning "initializer-string for array of 'char' is too long" } */ char t1[1] = { "xy" }; /* { dg-warning "initializer-string for array of 'char' is too long" } */ -char u[1] = { "x", "x" }; /* { dg-error "excess elements in 'char' array initializer" } */ +char u[1] = { "x", "x" }; /* { dg-error "excess elements in 'char.1.' initializer" } */ /* { dg-message "near init" "near" { target *-*-* } .-1 } */ int j = { 1 }; diff --git a/gcc/testsuite/gcc.dg/init-bad-3.c b/gcc/testsuite/gcc.dg/init-bad-3.c index c5c338d9a85..c22e8ec6698 100644 --- a/gcc/testsuite/gcc.dg/init-bad-3.c +++ b/gcc/testsuite/gcc.dg/init-bad-3.c @@ -19,7 +19,7 @@ char s[1] = "x"; char s1[1] = { "x" }; char t[1] = "xy"; /* { dg-error "initializer-string for array of 'char' is too long" } */ char t1[1] = { "xy" }; /* { dg-error "initializer-string for array of 'char' is too long" } */ -char u[1] = { "x", "x" }; /* { dg-error "excess elements in 'char' array initializer" } */ +char u[1] = { "x", "x" }; /* { dg-error "excess elements in 'char.1.' initializer" } */ /* { dg-message "near init" "near" { target *-*-* } .-1 } */ int j = { 1 }; diff --git a/gcc/testsuite/gcc.dg/init-excess-3.c b/gcc/testsuite/gcc.dg/init-excess-3.c index 7741261bd49..c03a98487b4 100644 --- a/gcc/testsuite/gcc.dg/init-excess-3.c +++ b/gcc/testsuite/gcc.dg/init-excess-3.c @@ -4,12 +4,12 @@ /* { dg-options "" } */ -char s0[] = {"abc",1}; /* { dg-error "array initializer|near init" } */ -char s1[] = {"abc","a"}; /* { dg-error "array initializer|near init" } */ -char s2[] = {1,"abc"}; /* { dg-error "array initializer|near init|computable at load time" } */ +char s0[] = {"abc",1}; /* { dg-error "'char..' initializer|near init" } */ +char s1[] = {"abc","a"}; /* { dg-error "'char..' initializer|near init" } */ +char s2[] = {1,"abc"}; /* { dg-error "'char..' initializer|near init|computable at load time" } */ /* { dg-warning "integer from pointer without a cast" "" { target *-*-* } .-1 } */ -char s3[5] = {"abc",1}; /* { dg-error "array initializer|near init" } */ -char s4[5] = {"abc","a"}; /* { dg-error "array initializer|near init" } */ -char s5[5] = {1,"abc"}; /* { dg-error "array initializer|near init|computable at load time" } */ +char s3[5] = {"abc",1}; /* { dg-error "'char.5.' initializer|near init" } */ +char s4[5] = {"abc","a"}; /* { dg-error "'char.5.' initializer|near init" } */ +char s5[5] = {1,"abc"}; /* { dg-error "'char.5.' initializer|near init|computable at load time" } */ /* { dg-warning "integer from pointer without a cast" "" { target *-*-* } .-1 } */ diff --git a/gcc/testsuite/gcc.dg/pr61096-1.c b/gcc/testsuite/gcc.dg/pr61096-1.c index f41789c5f52..90ffb8087d2 100644 --- a/gcc/testsuite/gcc.dg/pr61096-1.c +++ b/gcc/testsuite/gcc.dg/pr61096-1.c @@ -47,7 +47,7 @@ __extension__ int a15[10] = {[2 ... 1] = 4 }; /* { dg-error "31:empty index rang __extension__ int a16[10] = {[2 ... 100] = 4 }; /* { dg-error "31:array index range in initializer exceeds array bounds" } */ int a17[] = { .B = 1 }; /* { dg-error "15:field name not in record or union initializer" } */ int a18[] = { e }; /* { dg-error "15:initializer element is not constant" } */ -char a19[1] = { "x", "x" }; /* { dg-error "22:excess elements in 'char' array initializer" } */ +char a19[1] = { "x", "x" }; /* { dg-error "22:excess elements in 'char.1.' initializer" } */ void bar (void)