Last Update 2021/03/28
-fmax-errors=最大数
エラーメッセージの最大数を設定
テスト概要
-fmax-errors= オプションを使用せずにコンパイルを実行
警告を含む全てのメッセージを出力
-fmax-errors=3 を指定してコンパイルを実行
3つ目のエラーメッセージが出力された時点で出力停止
-fmax-errors=3 および -v オプションを指定してコンパイルを実行
停止までの詳細な出力を確認
-fmax-errors=4 を指定してコンパイルを実行
警告メッセージにはこのオプションは影響無し
-fmax-errors=0 を指定してコンパイルを実行
エラーメッセージ数に制限無し
-fmax-errors=3 および -Wfatal-errors オプションを指定してコンパイルを実行
-Wfatal-errorsが優先され、最初のエラーメッセージで停止
実行環境
GCC-8.2.0
GNU C Library 2.28
GNU Binutils 2.31.1
GNU C Library 2.28
GNU Binutils 2.31.1
コード例・出力内容中の表記
・実行例中の太字表記部分は、コマンドなどの入力された文字列を示します。
・「︙」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。
・「︙」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。
使用ファイル
main.c
/* -fmax-errors= オプション動作確認用ソースファイル */
#include <stdio.h>
int main(void)
{
int n;
int n;
int n;
int n;
printf("-fmax-errors= オプション動作確認用ソースファイル\n");
printtf("-fmax-errors= オプション動作確認用ソースファイル\n");
printttf("-fmax-errors= オプション動作確認用ソースファイル\n");
printtttf("-fmax-errors= オプション動作確認用ソースファイル\n");
return 0;
}
-fmax-errors= オプションを使用せずにコンパイルを実行
$ gcc main.c
main.c: In function ‘main’:
main.c:9:6: error: redeclaration of ‘n’ with no linkage
int n; エラーメッセージ
^
main.c:7:6: note: previous declaration of ‘n’ was here
int n; note
^
main.c:10:6: error: redeclaration of ‘n’ with no linkage
int n; エラーメッセージ
^
main.c:9:6: note: previous declaration of ‘n’ was here
int n; note
^
main.c:11:6: error: redeclaration of ‘n’ with no linkage
int n; エラーメッセージ
^
main.c:10:6: note: previous declaration of ‘n’ was here
int n; note
^
main.c:14:2: warning: implicit declaration of function ‘printtf’; did you mean ‘printf’? [-Wimplicit-function-declaration]
printtf("-fmax-errors= オプション動作確認用ソースファイル\n"); 警告
^~~~~~~
printf
main.c:15:2: warning: implicit declaration of function ‘printttf’; did you mean ‘printf’? [-Wimplicit-function-declaration]
printttf("-fmax-errors= オプション動作確認用ソースファイル\n"); 警告
^~~~~~~~
printf
main.c:16:2: warning: implicit declaration of function ‘printtttf’; did you mean ‘printf’? [-Wimplicit-function-declaration]
printtttf("-fmax-errors= オプション動作確認用ソースファイル\n"); 警告
^~~~~~~~~
printf
$ 警告含む全てのメッセージを出力して終了
-fmax-errors=3 を指定してコンパイルを実行
$ gcc -fmax-errors=3 main.c
main.c: In function ‘main’:
main.c:9:6: error: redeclaration of ‘n’ with no linkage
int n; エラーメッセージ
^
main.c:7:6: note: previous declaration of ‘n’ was here
int n; note
^
main.c:10:6: error: redeclaration of ‘n’ with no linkage
int n; エラーメッセージ
^
main.c:9:6: note: previous declaration of ‘n’ was here
int n; note
^
main.c:11:6: error: redeclaration of ‘n’ with no linkage
int n; エラーメッセージ
^
main.c:10:6: note: previous declaration of ‘n’ was here
int n; note
^
compilation terminated due to -fmax-errors=3.
$ 3つ目のエラーメッセージが出力された時点で出力停止(関連行のnoteメッセージを含む)
-fmax-errors=3 および -v オプションを指定してコンパイルを実行
$ gcc -v -fmax-errors=3 main.c
Using built-in specs.
︙
/usr/libexec/gcc/x86_64-pc-linux-gnu/8.2.0/cc1 -quiet -v main.c ... -fmax-errors=3 -o /tmp/ccVsuYLX.s
︙
GNU C17 (GCC) version 8.2.0 (x86_64-pc-linux-gnu)
compiled by GNU C version 8.2.0, GMP version 6.1.2, MPFR version 4.0.1, MPC version 1.1.0, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 84637943c330ccfe91c8483610cbfda9
main.c: In function ‘main’:
main.c:9:6: error: redeclaration of ‘n’ with no linkage
int n;
^
main.c:7:6: note: previous declaration of ‘n’ was here
int n;
^
main.c:10:6: error: redeclaration of ‘n’ with no linkage
int n;
^
main.c:9:6: note: previous declaration of ‘n’ was here
int n;
^
main.c:11:6: error: redeclaration of ‘n’ with no linkage
int n;
^
main.c:10:6: note: previous declaration of ‘n’ was here
int n;
^
compilation terminated due to -fmax-errors=3.
$ メッセージの出力停止と同時に処理自体が終了
-fmax-errors=4 を指定してコンパイルを実行
$ gcc -fmax-errors=4 main.c
main.c: In function ‘main’:
main.c:9:6: error: redeclaration of ‘n’ with no linkage
int n; エラーメッセージ(1)
^
main.c:7:6: note: previous declaration of ‘n’ was here
int n; note
^
main.c:10:6: error: redeclaration of ‘n’ with no linkage
int n; エラーメッセージ(2)
^
main.c:9:6: note: previous declaration of ‘n’ was here
int n; note
^
main.c:11:6: error: redeclaration of ‘n’ with no linkage
int n; エラーメッセージ(3)
^
main.c:10:6: note: previous declaration of ‘n’ was here
int n; note
^
main.c:14:2: warning: implicit declaration of function ‘printtf’; did you mean ‘printf’? [-Wimplicit-function-declaration]
printtf("-fmax-errors= オプション動作確認用ソースファイル\n"); 警告
^~~~~~~
printf
main.c:15:2: warning: implicit declaration of function ‘printttf’; did you mean ‘printf’? [-Wimplicit-function-declaration]
printttf("-fmax-errors= オプション動作確認用ソースファイル\n"); 警告
^~~~~~~~
printf
main.c:16:2: warning: implicit declaration of function ‘printtttf’; did you mean ‘printf’? [-Wimplicit-function-declaration]
printtttf("-fmax-errors= オプション動作確認用ソースファイル\n"); 警告
^~~~~~~~~
printf
$ エラーメッセージの以外はカウントされず、警告を含む全メッセージを出力
-fmax-errors=0 を指定してコンパイルを実行
$ gcc -fmax-errors=0 main.c
main.c: In function ‘main’:
main.c:9:6: error: redeclaration of ‘n’ with no linkage
int n;
^
main.c:7:6: note: previous declaration of ‘n’ was here
int n;
^
main.c:10:6: error: redeclaration of ‘n’ with no linkage
int n;
^
main.c:9:6: note: previous declaration of ‘n’ was here
int n;
^
main.c:11:6: error: redeclaration of ‘n’ with no linkage
int n;
^
main.c:10:6: note: previous declaration of ‘n’ was here
int n;
^
main.c:14:2: warning: implicit declaration of function ‘printtf’; did you mean ‘printf’? [-Wimplicit-function-declaration]
printtf("-fmax-errors= オプション動作確認用ソースファイル\n");
^~~~~~~
printf
main.c:15:2: warning: implicit declaration of function ‘printttf’; did you mean ‘printf’? [-Wimplicit-function-declaration]
printttf("-fmax-errors= オプション動作確認用ソースファイル\n");
^~~~~~~~
printf
main.c:16:2: warning: implicit declaration of function ‘printtttf’; did you mean ‘printf’? [-Wimplicit-function-declaration]
printtttf("-fmax-errors= オプション動作確認用ソースファイル\n");
^~~~~~~~~
printf
$ エラーメッセージ数に制限無し
警告含む全てのメッセージを出力して終了
上記結果はその1と同様の出力
-fmax-errors=3 および -Wfatal-errors オプションを指定してコンパイルを実行
$ gcc -fmax-errors=3 -Wfatal-errors main.c
main.c: In function ‘main’:
main.c:9:6: error: redeclaration of ‘n’ with no linkage
int n; エラーメッセージ
^
compilation terminated due to -Wfatal-errors.
$ -Wfatal-errorsが優先され、最初のエラーメッセージで停止