This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Re: Confusing error for incorrect struct initialization
- From: "lh mouse"<lh_mouse at 126 dot com>
- To: "Mason"<mpeg dot blue at free dot fr>
- Cc: "GCC help"<gcc-help at gcc dot gnu dot org>
- Date: Sun, 19 Jun 2016 02:01:48 +0800
- Subject: Re: Re: Confusing error for incorrect struct initialization
- Authentication-results: sourceware.org; auth=none
- References: <5764F614 dot 7060108 at free dot fr> <7cebec62 dot 21aed9 dot 155627c508f dot Coremail dot lh_mouse at 126 dot com> <5765760A dot 1050200 at free dot fr> <e9fd21b dot 21bb5d dot 155646493d6 dot Coremail dot lh_mouse at 126 dot com><576587F7 dot 2040404 at free dot fr>
From your point of view no C compiler could be 'good':
---
// gcc 6.1
test.c:4:20: error: initializer element is not constant
struct foo bar = { s }; /*** should be &s ***/
^
test.c:4:20: note: (near initialization for 'bar.p')
---
// clang 3.3
prog.c:4:20: error: initializing 'struct xxx *' with an expression of incompatible type 'struct xxx'; take the address with &
struct foo bar = { s }; /*** should be &s ***/
^
&
prog.c:4:22: warning: missing field 'e' initializer [-Wmissing-field-initializers]
struct foo bar = { s }; /*** should be &s ***/
^
---
// ICC 13.0
example.cpp(4): error: expression must have a constant value
struct foo bar = { s }; /*** should be &s ***/
---
// CL18 (a.k.a. MSVC)
test.c
test.c(4) : error C2099: initializer is not a constant
---
The error suppresses the warning here.
The standard is the standard. The WG14 people don't care what you would think about them and the language.
If you truly want to have some error messsages more friendly (thus helpful), particularly for your sample code above, you can be happy with C++.
------------------
Best regards,
lh_mouse
2016-06-19
-------------------------------------------------------------
åääïMason <mpeg.blue@free.fr>
åéææï2016-06-19 01:42
æääïlh mouse
æéïGCC help
äéïRe: Confusing error for incorrect struct initialization
On 18/06/2016 18:42, lh mouse wrote:
> Initializing a `int *` with an `int` has to be permitted.
> It is making it an error that would be a bug.
The code I'm interested in is:
struct xxx { void *p; int a,b,c,d; double x,y; };
struct foo { struct xxx *p; int e,f,g; };
struct xxx s;
struct foo bar = { s }; /*** should be &s ***/
(I don't see any int pointers there.)
Do you see the error on the last line?
What error message would you expect a good compiler to output?
Regards.