5 COMPILER DIAGNOSTICS

This chapter contains the following sections:

Diagnostic Messages
Termination Messages
Response to Signals
Return Values

5.1 Diagnostic Messages

Diagnostic messages have an associated severity, as follows:

By default, --tsw-diagnostics, diagnostics are written to stderr with a form like the following:

test.cc
     5:   break;
E  116: a break statement may only be used within a loop or switch  

With the command line option --no-tsw-diagnostics the message appear in the following form:

"test.cc", line 5: a break statement may only be used within a loop
          or switch
    break;
    ^

Note that the message identifies the file and line involved, and that the source line itself (with position indicated by the ^) follows the message. If there are several diagnostics in one source line, each diagnostic will have the form above, with the result that the text of the source line will be displayed several times, with an appropriate position each time.

Long messages are wrapped to additional lines when necessary.

A configuration flag controls whether or not the string error: appears, i.e., the C++ compiler can be configured so that the severity string is omitted when the severity is error.

The command line option --brief-diagnostics may be used to request a shorter form of the diagnostic output in which the original source line is not displayed and the error message text is not wrapped when too long to fit on a single line.

The command line option --display-error-number may be used to request that the error number be included in the diagnostic message. When displayed, the error number also indicates whether the error may have its severity overridden on the command line (with one of the --diag-severity options). If the severity may be overridden, the error number will include the suffix -D (for discretionary); otherwise no suffix will be present.

"Test_name.cc", line 7: error #64-D: declaration does not 
          declare anything
  struct ;
  ^
"Test_name.cc", line 9: error #77: this declaration has no storage
          class or type specifier
  xxxxx;
  ^

Because an error is determined to be discretionary based on the error severity associated with a specific context, a given error may be discretionary in some cases and not in others.

For some messages, a list of entities is useful; they are listed following the initial error message:

"test.cc", line 4: error: more than one instance of overloaded
          function "f" matches the argument list:
            function "f(int)"
            function "f(float)"
            argument types are: (double)
    f(1.5);
    ^

In some cases, some additional context information is provided; specifically, such context information is useful when the C++ compiler issues a diagnostic while doing a template instantiation or while generating a constructor, destructor, or assignment operator function. For example:

"test.cc", line 7: error: "A::A()" is inaccessible
  B x;
     ^
          detected during implicit generation of "B::B()" at line 7

Without the context information, it is very hard to figure out what the error refers to.

For a list of error messages and error numbers, see Appendix B, Error Messages.

5.2 Termination Messages

cptc writes sign-off messages to stderr if errors are detected. For example, one of the following forms of message

is written to indicate the detection of errors in the compilation. No message is written if no errors were detected.

is written when the count of errors reaches the error limit (see the -e option); compilation is then terminated. The message

is written at the end of a compilation that was prematurely terminated because of a catastrophic error. The message

is written at the end of a compilation that was prematurely terminated because of an internal error. Such an error indicates an internal problem in the compiler. If such an internal error appears, please report the occurrence to TASKING, using a Problem Report form. Please include a diskette or tape, containing a small C++ program causing the error.

5.3 Response to Signals

The signals SIGINT (caused by a user interrupt, like ^C) and SIGTERM (caused by a kill command) are trapped by the C++ compiler and cause abnormal termination.

5.4 Return Values

cptc returns an exit status to the operating system environment for testing.

For example,

in a PC BATCH-file you can examine the exit status of the program executed with ERRORLEVEL:

In a Bourne shell script, the exit status can be found in the $? variable, for example:

The exit status of cptc indicates the highest severity diagnostic detected and is one of the numbers of the following list:

When you used the command line option --warnings-as-errors, the exit status will be 2 when there were warnings.


Copyright © 2003 Altium BV