Re: Confusing error for incorrect struct initialization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 06/18/2016 10:25 AM, Mason wrote:
On 18/06/2016 09:49, lh mouse wrote:

Mason wrote:

I opened bug 71552:

"Confusing error for incorrect struct initialization"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71552

I don't understand Martin's reply in comment #1.

Could someone explain?

Those are GCC implementation details.

In spite that in most cases implicit conversion from an integer
(except a null pointer constant, of course) to a pointer should be
considered a casual error, it is however required by the C standard:

Making it an error would make GCC not conform to the standard just
because C is so broken.

/me scratches head... Making what an error?

The bug is a request to improve an existing error message.

struct xxx { void *p; int a,b,c,d; double x,y; };
struct foo { struct xxx *p; int e,f,g; };
static struct xxx s = { 0 };
struct foo bar = { s }; /*** should be &s ***/

$ gcc-6 -c qoi.c
qoi.c:4:20: error: initializer element is not constant
  struct foo bar = { s }; /*** should be &s ***/
                     ^
qoi.c:4:20: note: (near initialization for 'bar.p')


Do you disagree that this is a confusing error message?

Isn't this one better:

   incompatible types when initializing type 'struct xxx *' using type 'struct xxx'

I agree that in this case the error is misleading because even
if s could somehow be made a constant expression (it can't be
because its type isn't one of those required of constant
expressions in initializers) it would not be a valid initializer
for a pointer.  It seems straightforward to check that the
initializer type is compatible first, before checking its
constness, and issue the clearer error message instead. Let
me finish the patch I prototyped for it and post it for review.

Martin

PS Note that this case is different from the one submitted in
bug 71552 and my patch does not change the error GCC issues
for it for the reasons explained there.  I.e., initializing
a pointer with an integer is valid in C and cannot very well
be rejected.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux