Intel® C++ Compiler Classic Developer Guide and Reference

ID 767249
Date 12/16/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Error Handling

This topic describes compiler remarks, warnings, and errors. The compiler sends these messages, along with the erroneous source line, to stderr.

Warnings

Warning messages report legal but questionable use of C or C++. The compiler displays warnings by default. You can suppress warning messages by specifying an appropriate compiler option. Warnings do not stop translation or linking. Warnings do not interfere with any output files.

The following are some representative warning messages:

declaration does not declare anything
pointless comparison of unsigned integer with zero
possible use of = where == was intended

Some warnings that start with -W can be disabled using the negative form of the option -Wno-. For example, option -Wno-unknown-pragmas disables option -Wunknown-pragmas.

Linux and macOS

Additional Warnings

The following Linux* and macOS options produce additional warnings:

Option

Result

-W[no-]missing-prototypes

Warn for missing prototypes.

-W[no-]missing-declarations

Warn for missing declarations.

-W[no-]unused-variable

Warn for unused variable.

-W[no-]pointer-arith

Warn for questionable pointer arithmetic.

-W[no-]uninitialized

Warn if a variable is used before being initialized.

-W[no-]deprecated

Display warnings related to deprecated features.

-W[no-]abi

Warn if generated code is not C++ ABI compliant.

-W[no-]unused-function

Warn if declared function is not used.

-W[no-]unknown-pragmas

Warn if an unknown #pragma directive is used.

-W[no-]main

Warn if return type of main is not expected.

-W[no-]comment[s]

Warn when /* appears in the middle of a /* */ comment.

-W[no-]return-type

Warn when a function uses the default int return type
Warn when a return statement is used in a void function.

Errors

These messages report syntactic or semantic misuse of C or C++. The compiler always displays error messages. Errors suppress object code for the module containing the error and prevent linking, but they allow parsing to continue to detect other possible errors.

The following are some representative error messages:

missing closing quote
expression must have arithmetic type
expected a ";"

Remarks

Remark messages report common but sometimes unconventional use of C or C++. Remarks do not stop translation or linking. Remarks do not interfere with any output files.

The following are some representative remark messages:

function declared implicitly
type qualifiers are meaningless in this declaration
controlling expression is constant

Some remarks, warnings, and errors are numbered and can be disabled using option -diag-disable=list or /Qdiag-disable:list.

Example

Linux and macOS

-diag-disable=117,230,450

Windows

/Qdiag-disable:117,230,450

Option Summary

You can use the following compiler options to control remarks, warnings, and errors.

Linux and macOS

Option

Result

-w

Enables diagnostics for errors; disables diagnostics for warnings.

-w1

Enables diagnostics for warnings and errors.

-w2

Enables diagnostics for verbose warnings, warnings, and errors.

-w3

Enables diagnostics for remarks, warnings, and errors. Additional warnings are also enabled above level 2 warnings.

-Wremarks

Display remarks and comments.

-Wbrief

Display brief one-line diagnostics.

-Wcheck

Enable more strict diagnostics.

-Werror-all

Change all warnings and remarks to errors.

-Werror

Change all warnings to errors.

Windows

Option

Result

/W0

Enables diagnostics for errors; disables diagnostics for warnings.

/W1, /W2

Enables diagnostics for warnings and errors.

/W3

Enables diagnostics for remarks, warnings, and errors. Additional warnings are also enabled above level 2 warnings.

/W4, /Wall

Enables diagnostics for all level 3 warnings, plus informational warnings and remarks, which, in most cases, can be safely ignored.

/W5

Enables diagnostics for all remarks, warnings, and errors. This option produces the most diagnostic messages.

/WL

Display brief one-line diagnostics.

/WX

Change all warnings to errors.

/Wp64

Display diagnostics for 64-bit porting.

You can also control the display of diagnostic information with variations of the [Q]diag compiler option. This compiler option accepts numerous arguments and values, allowing you wide control over displayed diagnostic messages and reports.

Some of the most common variations include the following:

Option

Result

[Q]diag-enable<:|=>list

Enables a diagnostic message or a group of messages.

[Q]diag-disable<:|=>list

Disables a diagnostic message or a group of messages.

[Q]diag-warning<:|=>list

Tells the compiler to change diagnostics to warnings.

[Q]diag-error<:|=>list

Tells the compiler to change diagnostics to errors.

[Q]diag-remark<:|=>list

Tells the compiler to change diagnostics to remarks (comments).

The list items can be specific diagnostic IDs, one of the keywords warn, remark, or error, or a keyword specifying a certain group (par, vec, driver, thread, port-linux (available on Windows* systems), port-win (available on Linux* and macOS systems), or openmp). For more information, see [Q]diag.

Other diagnostic-related options include the following:

Option

Result

[Q]diag-dump

Tells the compiler to print all enabled diagnostic messages and stop compilation.

[Q]diag-file[<:|=>file]

Causes the results of diagnostic analysis to be output to a file.

[Q]diag-file-append[<:|=>file]

Causes the results of diagnostic analysis to be appended to a file.

[Q]diag-error-limit<:|=>n

Specifies the maximum number of errors allowed before compilation stops.