Loose-Info.com
Last Update 2021/09/10
TOP - 各種テスト - gcc - 警告関連のオプション - -Wmisleading-indentation

-Wmisleading-indentation
コードのインデントがブロック構造と一致していない場合に警告を出力

テスト概要

オプション無し、-Wmisleading-indentation、-Wallの各オプションを使用した際の警告出力例

実行環境

GCC-8.2.0
GNU C Library 2.28
GNU Binutils 2.31.1


コード例・出力内容中の表記

・実行例中の太字表記部分は、コマンドなどの入力された文字列を示します。
・「」や「...」の着色省略表記は、 実際のソースコードや出力内容などを省略加工した部分を示します。

使用ファイル


sample.c
#include <stdio.h> int main(void) { int i; for (i=0; i<3; i++) printf("i = %d\n", i); /* これ以降はfor文の外側 */ printf("test\n"); return 0; }

動作テスト

オプション無しでコンパイルを実行
$ gcc sample.c 警告無し $ ./a.out i = 0 i = 1 i = 2 test 「test」の出力はブロック構造の外側 $

-Wmisleading-indentationオプション使用してコンパイルを実行
$ gcc -Wmisleading-indentation sample.c sample.c: In function ‘main’: sample.c:7:2: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation] for (i=0; i<3; i++) ^~~ sample.c:10:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’ printf("test\n"); ^~~~~~ $ 「for」のブロック範囲と誤解を与えそうなインデンドの位置に関する警告と注記

-Wallオプション使用してコンパイルを実行
$ gcc -Wall sample.c sample.c: In function ‘main’: sample.c:7:2: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation] for (i=0; i<3; i++) ^~~ sample.c:10:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’ printf("test\n"); ^~~~~~ $ -Wallに-Wmisleading-indentationが含まれるため関連する警告を出力