C, Ocean Edition I

Annex I. Diagnostics

Annex
I
ISO C99 mapping
new
Status
Clause I.2 is normative. Clause I.3 is a recommendation.

I.0 The Principle

An implementation shall diagnose an error it can already prove.

A deterministic language should use the knowledge it already possesses. Where a program construct is invalid and the invalidity is evident at translation time, silence is not a conforming response. See clause 4.3 and behavior.md section 108.

This annex separates what an implementation shall diagnose from what it should diagnose. The first list is a conformance requirement. The second is the difference between an implementation that meets the specification and one that is good.


I.1 Categories

Error. Translation stops. The program is not translated into an executable form. Every constraint violation is an error.

Warning. Translation continues and the meaning of the program is unchanged. Under the strict profile of clause 4.6.3, every warning in clause I.3 becomes an error.

Note. Additional information attached to an error or a warning, such as the location of a conflicting declaration. Notes are recommended and are never required.

Quality requirements.

A diagnostic shall name the source location of the construct. A diagnostic for a redeclaration, a conflict, or a shadowing shall also name the location of the other declaration. A diagnostic for a removed construct shall name the replacement spelling, and should offer the rewrite as an applicable fix.


I.2 Required Diagnostics

Each of these is an error unless it is marked as a warning.

I.2.1 Constraint violations

Every constraint violation stated anywhere in clause 5, clause 6, or clause 7. This is the largest group and it is not repeated here.

I.2.2 Removed constructs

I.2.3 Canonicalization

I.2.4 Provable arithmetic errors

Where the operands are constants or are otherwise statically known on a reachable path:

I.2.5 Provable memory errors

I.2.6 Control flow

I.2.7 Types and declarations

I.2.8 Library

I.2.9 Mixed signedness in arithmetic

Warning. An arithmetic operation in which a signed operand is converted to an unsigned type by the usual arithmetic conversions, where the signed operand is not known to be nonnegative. Clause 6.3.1.6.

This is required because it is the most common source of silent arithmetic surprise remaining in the edition. Comparison was fixed by clause 6.3.1.7. Arithmetic was left compatible with C, and this warning is the price of that compatibility.

I.2.10 Fallthrough

Warning. A fallthrough from a nonempty case group into another labeled group. Clause 6.8.4.2.

The implementation shall provide a documented way to suppress it for an intentional fallthrough.

I.2.11 Limits

I.2.12 Namespaces

I.2.13 Reproducibility


I.3 Recommended Diagnostics

These are warnings. An implementation should produce them by default, and shall document which ones it produces. The strict profile promotes them to errors.

I.3.1 Expressions

I.3.2 Declarations

I.3.3 Control flow

I.3.4 Style and idiom


I.4 What an Implementation Shall Not Diagnose


I.5 Recommended Practice

A diagnostic should tell the programmer three things: what is wrong, where it is, and what to write instead. The third is the one most implementations omit, and it is the one that makes migration fast.

For a removed construct, the diagnostic should carry an applicable fix, so that a whole codebase can be migrated by applying fixes rather than by hand editing. Nearly every removal in this edition has a mechanical rewrite, and clause H.1.2 lists them.