MISRA Discussion Forums
Dir 2.1 compilation errors - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 7.2 Compilation and build (https://forum.misra.org.uk/forumdisplay.php?fid=179)
+---- Thread: Dir 2.1 compilation errors (/showthread.php?tid=1028)



Dir 2.1 compilation errors - ogawa.kiyoshi - 18-02-2014

In Dir 2.1 , "A conforming compiler is permitted to produce an object module despite the presence of compilation errors."
I should explain this situation for the programmers, but I do not know any real compilers, producing an object module with the presence of compilation errors.
Do anyone know a compiler which can produce an object module with the presence of compilation errors?

Dr. Ogawa Kiyoshi.
@kaizen_nagoya
http://researchmap.jp/kaizen/MISRA-C/


Re: Dir 2.1 compilation errors - misra-c - 26-02-2014

We will start by giving some more background to the use of the term "compiler error".

A conforming C implementation (C99 5.1.1.3) must produce at least one diagnostic message if there is a violation of the C syntax or a constraint is broken. However, there is no restriction on the form of the message, the number of messages or whether object code is produced . We will refer to such violations are "constraint errors".

Users tend to refer to these diagnostics as "compiler errors" and "compiler warnings", but these are not terms that are defined in the standard. A compiler may choose whether a "constraint error" produces a "compiler error" or a "compiler warning". The following example contains a "constraint error", but the gcc(v3.4) compiler produces a "compiler warning" and object code.
Code:
void foo (void)
{
  return 0;  // Violates constraint in C99 6.8.6.4
             // A return statement with an expression shall not appear in a function whose return type is void.
}

int main (void)
{
  foo();
  return 0;
}
Another example of a "compiler warning" in gcc occurs when assigning an integer value to a pointer or vice versa without using a cast. This is not to say that gcc is incorrect, since a compiler is free to choose whether object code is issued in such circumstances.

Directive 2.1 refers to "compiler errors" and it is a directive rather than a rule, because we cannot define what a particular compiler will treat as an "error". You may subjectively think you know what it means, but it is impossible to define precisely. It may, for example, be a particular level of warning, or perhaps those messages preceded by the word "Error" in English or by a different word in another language.

All "constraint errors" are covered by rule 1.1 of the MISRA C:2012 guidelines, but may also violate directive 2.1. Directive 2.1 also covers other issues that a particular compiler considers are serious. These may be messages concerning undefined behaviour (e.g. index out of bounds) or a misuse of a language extension.

As we have shown in the example above, some compilers will produce object code in the presence of a "constraint error". We do not have an example of a compiler which produces object code for a "compiler error", but this is not prevented by the C standard and so must be allowed for.