1.24. Enforcing Strict Conformance to the C++ Standard
Problem
You want your compiler to accept only programs that conform to the C++ language standard.
Solution
Command-line options for specifying strict conformance to the C++ standard are listed in Table 1-37. Instructions for enforcing strict conformance from your IDE are given in Table 1-38.
Tip
Some of the compiler options I introduced in Table 1-6 can be considered conformance options. Examples include options to enable basic language features such as wide-character support, exceptions, and runtime type information. I’ve omitted these in Table 1-37.
Table 1-37. Enforcing strict conformance from the command line
|
Toolset |
Command-line compiler options |
|---|---|
|
GCC |
-ansi -pedantic-errors |
|
Visual C++ |
-Za |
|
Intel (Windows) |
-Za -Qms0 |
|
Intel (Linux) |
-strict-ansi [19] |
|
Metrowerks |
-ansi strict -iso_templates on -msext off |
|
Comeau (Windows) |
—A |
|
Comeau (Unix) |
—strict or -A |
|
Borland |
-A [20] |
|
Digital Mars |
-A |
[19] Versions of the Intel compiler for Linux prior to 9.0 used the option -strict_ansi. When using -strict-ansi or -strict_ansi, it may be necessary to enable Intel’s standard library, using the option -cxxlib-icc. [20] With the option -A, some of the standard headers from the STLPort library may fail to compile. | |
Table 1-38. Enforcing strict conformance from your IDE
|
IDE |
Configuration |
|---|---|
|
Visual C++ |
From your project’s property pages, go to Configuration Properties→ C/C++→ Language and set Disable Language Extensions, ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access