[Bug c/71552] New: Confusing error for incorrect struct initialization
mpeg.blue at free dot fr
gcc-bugzilla@gcc.gnu.org
Thu Jun 16 09:27:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71552
Bug ID: 71552
Summary: Confusing error for incorrect struct initialization
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: mpeg.blue at free dot fr
Target Milestone: ---
I'm using gcc version 6.1.1 20160511 (Ubuntu 6.1.1-3ubuntu11~14.04.1)
Consider the following code.
struct foo { const int *p; };
static const int i = 42;
struct foo bar = { i }; /*** should be &i ***/
NOTA BENE: the initialization of bar is incorrect
(because an int is provided, instead of a pointer to int)
I expected an error message along the lines of
"initializer for bar.p has an incompatible type"
but instead, I got
qoi.c:3:20: error: initializer element is not constant
struct foo bar = { i }; /*** should be &i ***/
^
qoi.c:3:20: note: (near initialization for 'bar.p')
"initializer element is not constant" ?
Is there a simple way to improve the error message?
More information about the Gcc-bugs
mailing list