This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/59520] a possible inconsistency in error diagnostics with "-pedantic -std=c99"


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59520

--- Comment #4 from Zhendong Su <su at cs dot ucdavis.edu> ---
Joesph and Manuel, thanks for the discussions and clarifications on the
inconsistency.  

It would be nice to see that this gets fixed eventually. I remember that Peter
Norvig has commented not too long ago --- in the context of MOOCs (i.e.
massively open online classes) --- that compiler error messages are typically
very hard for beginners to make sense and scares them away from learning
programming, so it would be great to see this aspect of compilers also gets
better to become more "friendly" to beginners (and professionals too). 

I also noticed the following piece of relevant GCC documentation: 

http://gcc.gnu.org/onlinedocs/gcc/Warnings-and-Errors.html

The following paragraph is particularly relevant to our discussion: 

"GCC always tries to compile your program if possible; it never gratuitously
rejects a program whose meaning is clear merely because (for instance) it fails
to conform to a standard. In some cases, however, the C and C++ standards
specify that certain extensions are forbidden, and a diagnostic must be issued
by a conforming compiler. The -pedantic option tells GCC to issue warnings in
such cases; -pedantic-errors says to make them errors instead. This does not
mean that all non-ISO constructs get warnings or errors." 

The examples seem to fall into the category of "... whose meaning is clear ...
but merely fails to conform to the standard." 


-------------

Let me raise another question that is unrelated, but perhaps you folks, in
particular Joseph, could help add some clarify as I have been baffled by a
couple of examples. 

In particular, are the following well-defined according the standard or they
have undefined behavior? 

Ex 1
==== 

int printf (const char *, ...);

union
{
  int f0;
  char f1;
} d;

int
main ()
{
  d.f1 = 0;
  printf ("%d\n", d.f0);
  return 0;
}


Ex 2
====

int printf (const char *, ...);

struct S0
{
  char f0;
  int f1;
};

union
{
  int f0;
  struct S0 f1;
} d;

int
main ()
{
  struct S0 g = {0,0};
  d.f1 = g;
  printf ("%d\n", d.f0);
  return 0;
}


I'm quite sure that the first one is well-defined, and it's the second one that
baffles me (and GCC and Clang/LLVM behave differently on Ex 2). 

Thanks for any insight.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]