Arthur J. O'Dwyer wrote...
So when you see a required diagnostic, it's invariably your belief
that the code is well defined
Depends what you mean. My computer is physically incapable of
producing "undefined" byte values, so my source code is always
well-defined. Of course, if one of my programs violates a
constraint, then my C compiler issues a diagnostic and refuses
to compile the code, as required and allowed, respectively, by
the Standard. So there does not exist any "program", nor any
"behavior", defined or otherwise, associated with a program
which is not correct C. IMHO.
and the warning/error is spurious
'Course not! The error would specify (if I'm lucky) which
constraint had been violated, so I could fix it.
and purely there because the standard writers thought the
compiler should say something of no practical significance?!!
That doesn't make sense. A "C program" which does not compile
is not, technically speaking, a C program. It's *almost* a
program, but if it's not something that a C compiler can accept,
then I wouldn't call it a C program. And in this newsgroup, we
only talk about the "(un)defined behavior" of C programs.
You have Mike to thank for the quote originally. In some random act of
madness you decided to snip it when I first ticked it as a suitable
example!
Did you? Sorry.
If you want another I pulled up the very first constraint header 6.4p2
and took about half a second to come up with...
putchar('x);
How does that invoke UB? In fact, how exactly does that violate
a constraint? I'm having a hard time reading the Standard tonight;
I know there's some prohibition about unterminated character constants
in there somewhere, but I can't find it...
My original point was that a required diagnostic is, more often than
not, as much for the undefined behaviour as for the constraint
violation. Certainly, that's how I've always perceived compiler
errors.
Nope. UB was basically left "undefined" *because* it was so hard
to diagnose. Stuff like modifying string literals, for example.
If it's easy for the compiler to catch, it's almost always given
as a constraint.
But I have to ask both Mike and yourself, what do you think
constraints are for? Why bother with them if they only report well
defined code?
They don't report well-defined code; they report text which is *not*
code -- not C code, anyways. As I see it (slight repetition of above),
we have:
"C programs" with constraint violations: do not compile, thus
are not *really* written in C. E.g., your average C++
program violates several constraints. So does your average
Shakespearean sonnet. So do lots of things that *look* very
similar to real C programs, but contain typos or "thinkos."
C programs which exhibit undefined behavior. These programs
aren't required to elicit diagnostics, but their exact
behavior isn't defined either.
C programs without undefined behavior, which of course can be
further broken down into "conforming," "strictly conforming,"
et cetera. These are programs that AFAIK must always
compile and execute "correctly," without refusing to compile
or blowing things up.
HTH,
-Arthur