Richard Heathfield <rj*@see.sig.invalidwrites:
jacob navia said:
[...]
>Besides, MSVC emitted just a warning for repeated qualifiers like
"const long const long"... Isn't that an error?
It's a constraint violation, requiring a diagnostic message. It appears
that in this case MSVC /does/ issue a diagnostic message, so that's fine.
As discussed elsethread, it's a constraint violation in C90 but not in
C99. (I seem to recall that MSVC doesn't support, or claim to
support, C99.) Either way, the warning means they're ok. At least,
it *probably* does; see below.
>gcc wrote correct diagnostics for all of them, and all were errors,
not warnings.
The Standard makes no distinction. The Standard uses the term "diagnostic
messages". Errors and warnings are effectively mere vernacular terms.
>PellesC missed "const long const long" completely, but the errors
were as I had it: just "Invalid type specification" instead of a
more specific error.
As long as a diagnostic message is produced, that's not a conformance
problem.
To digress a bit from the original question ...
C99 defines a "diagnostic message" as a "message belonging to an
implementation-defined subset of the implementation's message output".
C99 5.1.1.3 says:
A conforming implementation shall produce at least one diagnostic
message (identified in an implementation-defined manner) if a
preprocessing translation unit or translation unit contains a
violation of any syntax rule or constraint, even if the behavior
is also explicitly specified as undefined or
implementation-defined. Diagnostic messages need not be produced
in other circumstances.
with a (non-normative) footnote:
The intent is that an implementation should identify the nature
of, and where possible localize, each violation. Of course, an
implementation is free to produce any number of diagnostics as
long as a valid program is still correctly translated. It may also
successfully translate an invalid program.
What hadn't fully sunk in until now is that "diagnostic messages" are
a *subset* of the implementation's message output, and the
implementation is required to document which messages are diagnostic.
Very strictly speaking, a message that says "Constraint violation on
line 42" isn't sufficient if the implementation's documentation
doesn't say that that's a "diagnostic message".
More realistically, an implementation could say in its documentation
that warnings (perhaps messages that start with "warning: ") don't
count as "diagnostic messages" within the meaning of the standard.
The intent would be that all syntax errors and constraint violations
produce actual error messages, not mere warnings. (<OT>gcc obviously
has no such policy.</OT>)
In other words, the standard doesn't distinguish between warnings and
error messages, but an implementation may do so in such a way that the
distinction is significant.
If such an implementation, in response to this:
const int const x = 42;
prints this:
warning: redundant "const" qualifier
then this would be a conformance failure for C90 (but not for C99,
which allows the redundant "const" qualifier).
I don't know what how actual implementations define "diagnostic
messages".
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"