2

If "shall / shall not" requirement is violated, then does it matter in which section (e.g. semantics, constraints) such requirement is located?

Reason of the question: this opinion:

This is in a Semantics section of the standard, not Constraints, so no diagnostic is required.

Is it true that violation of "shall / shall not" requirement located in the Semantics section does not require a diagnostics?

pmor
  • 5,392
  • 4
  • 17
  • 36

2 Answers2

5

Semantic violations do not require a diagnostic message, while constraint violations do.

Section 5.1.1.3p1 of the C11 standard regarding Diagnostics states the following:

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.

dbush
  • 205,898
  • 23
  • 218
  • 273
1

The standard only very loosely defines what "semantics" actually mean. Most importantly, there is no definition of the term in section 3 Terms, definitions, and symbols of the standard.

What the standard does define in that section is the meaning of "constraint":

3.8

1 constraint

restriction, either syntactic or semantic, by which the exposition of language elements is to be interpreted

Added emphasis on "...or semantic".

The standard then goes on:

4. Conformance

1 In this document, "shall" is to be interpreted as a requirement on an implementation or on a program; conversely, "shall not" is to be interpreted as a prohibition.

2 If a "shall" or "shall not" requirement that appears outside of a constraint or runtime-constraint is violated, the behavior is undefined.

And then we come to:

5.1.1.3 Diagnostics

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

Added emphasis on "...or constraint".

As per 3.8, being "only" a semantic restriction does not rule out something being a constraint.

As per 4. 1), a "shall" is a requirement, a "shall not" a prohibition.

I interpret both to indicate a constraint.

As per 5.1.1.3, not only violated syntax rules, but also violated constraints require a diagnostic, even if (as per 4. 2)) "[...] the behavior is also explicitly specified as undefined or implementation-defined."


Note, however, to avoid misunderstandings:

I am referring here to semantics specified with a "shall" / "shall not" in the standard, not any which semantics of any which program.

DevSolar
  • 67,862
  • 21
  • 134
  • 209