pmor
pmor

Reputation: 6296

Does "strictly conforming program" + no extensions mean "no diagnostics emitted"?

Follow-up question for: clang: <string literal> + <expression returning int> leads to confusing warning: adding 'int' to a string does not append to the string.

Does "strictly conforming program" + no extensions mean "no diagnostics emitted"?

Reason: better understanding of the term "strictly conforming program".

Upvotes: 1

Views: 107

Answers (2)

John Bollinger
John Bollinger

Reputation: 181244

Does "strictly conforming program" + no extensions == no diagnostics emitted?

No.

The only things for which the language specification requires diagnostics to be emitted are invalid syntax and constraint violations:

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.

(C2017, 5.1.1.3/1; emphasis added)

By definition, a strictly conforming program exhibits only valid syntax and does not contain any constraint violations, therefore the specification does not require a conforming implementation to emit any diagnostics when presented with such a program.

HOWEVER, the specification does not forbid implementations to emit diagnostics other than those that are required, and most implementations do, under some circumstances, emit diagnostics that are not required. The specification allows this, as clarified by footnote 9, which says, in part:

Of course, an implementation is free to produce any number of diagnostics as long as a valid program is still correctly translated.

Note also that "'strictly conforming program' + no extensions" is redundant. A program that makes use of any language extensions may conform, but it does not strictly conform:

A strictly conforming program shall use only those features of the language and library specified in this International Standard. It shall not produce output dependent on any unspecified, undefined,or implementation-defined behavior, and shall not exceed any minimum implementation limit.

(C2017 4/5; emphasis added)

Upvotes: 2

dbush
dbush

Reputation: 224972

An implementation may generate diagnostics even if a program is conforming.

Section 5.1.1.3p1 of the C standard regarding diagnostics states:

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.9)


  1. 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

The portion in bold in footnote 9 states that additional diagnostics may be produced.

Upvotes: 5

Related Questions