In said:
[snip]
I don't believe a constraint violation results in undefined behavior,
but IANACLL (xref: 6.5.16.1p1 and 4p1).
I should qualify that with "c.v. doesn't necessarily result in u'd.b.".
[snip]
Like I said, IANACLL, but my understanding was that the behavior of a
constraint violation is unspecified behavior, not undefined behavior.
Since I have only be looking at the assignment operator, this statement
should be restricted to the assignment in question:
char c = 'a';
int *p = &c;
BTW, if it wasn't clear before, my xref's are against C99.
The C standard doesn't classify constraint violations in several
categories. ALL of them have the same effect: a diagnostic is required
after which there are no more requirements from the implementation.
An implementation aborting the translation process after issuing a
required diagnostic would be perfectly conforming.
I think this is true of C89. But, C99 seems to have changed things.
For one thing:
xref 4p2: If a "shall" or "shall not" requirement that appears
outside of a constraint is violated, the behavior is undefined.
And this sentence is repeated in the Appendix the summarizes
undefined behaviors. If a constraint violation implied undefined
behavior, I believe the standard would not have bothered to state
this exception.
As to the particular assignment, there is a curious example in the
standard:
xref 6.5.16.1p6: EXAMPLE3: Consider the fragment:
const char **cpp;
char *p;
const char c = 'A';
cpp = &p; // constraint violation
*cpp = &c; // valid
*p = 0; // valid
The first assignment is unsafe because it would allow the
following valid code to attempt to change the value of the
const object c.
It seems the standard is implying the statement with the constraint
violation still has valid semantics.
If all C compilers failed to translate code *requiring* a diagnostic,
C would be a better known language.
Better known? Perhaps just better...
Far too many incompetents discard
ALL the warnings by default, without trying to understand if they signal
a real problem or not.
This point cannot be made often enough.
-- James