yohhoyの日記

技術的メモをしていきたい日記

GCC -pedanticオプション

GCCコンパイラの -pedantic オプションについてメモ。

pedantic
形容詞
〈侮蔑的〉〔文法・学問的なことなどについて〕重要でない事にこだわり過ぎる、学者ぶった、知識をひけらかす、衒学的な

https://eow.alc.co.jp/search?q=pedantic

GCC 2.95.3マニュアル*1より引用。下線部は後続バージョン(3.0)で削除された内容。

-pedantic
Issue all the warnings demanded by strict ANSI C and ISO C++; reject all programs that use forbidden extensions.

Valid ANSI C and ISO C++ programs should compile properly with or without this option (though a rare few will require `-ansi'). However, without this option, certain GNU extensions and traditional C and C++ features are supported as well. With this option, they are rejected.

`-pedantic' does not cause warning messages for use of the alternate keywords whose names begin and end with `__'. Pedantic warnings are also disabled in the expression that follows __extension__. However, only system header files should use these escape routes; application programs should avoid them. See section 4.35 Alternate Keywords.

This option is not intended to be useful; it exists only to satisfy pedants who would otherwise claim that GCC fails to support the ANSI standard.

Some users try to use `-pedantic' to check programs for strict ANSI C conformance. They soon find that it does not do quite what they want: it finds some non-ANSI practices, but not all--only those for which ANSI C requires a diagnostic.

A feature to report any failure to conform to ANSI C might be useful in some instances, but would require considerable additional work and would be quite different from `-pedantic'. We don't have plans to support such a feature in the near future.

https://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_2.html#SEC8

GCC 3.0マニュアル*2より引用(下線部は追加内容)。2024年1月現在の最新版GCC 13.2.0マニュアルでもほぼ同一内容。

-pedantic
Issue all the warnings demanded by strict ISO C and ISO C++; reject all programs that use forbidden extensions, and some other programs that do not follow ISO C and ISO C++. For ISO C, follows the version of the ISO C standard specified by any `-std' option used.

Valid ISO C and ISO C++ programs should compile properly with or without this option (though a rare few will require `-ansi' or a `-std' option specifying the required version of ISO C). However, without this option, certain GNU extensions and traditional C and C++ features are supported as well. With this option, they are rejected.

`-pedantic' does not cause warning messages for use of the alternate keywords whose names begin and end with `__'. Pedantic warnings are also disabled in the expression that follows __extension__. However, only system header files should use these escape routes; application programs should avoid them. See section 5.39 Alternate Keywords.

Some users try to use `-pedantic' to check programs for strict ISO C conformance. They soon find that it does not do quite what they want: it finds some non-ISO practices, but not all--only those for which ISO C requires a diagnostic, and some others for which diagnostics have been added.

A feature to report any failure to conform to ISO C might be useful in some instances, but would require considerable additional work and would be quite different from `-pedantic'. We don't have plans to support such a feature in the near future.

Where the standard specified with `-std' represents a GNU extended dialect of C, such as `gnu89' or `gnu99', there is a corresponding base standard, the version of ISO C on which the GNU extended dialect is based. Warnings from `-pedantic' are given where they are required by the base standard. (It would not make sense for such warnings to be given only for features not in the specified GNU C dialect, since by definition the GNU dialects of C include all features the compiler supports with the given option, and there would be nothing to warn about.)

https://gcc.gnu.org/onlinedocs/gcc-3.0/gcc_3.html#SEC11

関連URL

*1:GCC 2.95.3は2.x系の最終バージョン。2001年3月リリース。

*2:GCC 3.0は2001年6月リリース。GCC 2.x系からの大幅な変更・改善が行われている。https://www.gnu.org/software/gcc/gcc-3.0/features.html