Loose-Info.com
Last Update 2021/11/06
TOP - 各種テスト - gcc - 警告関連のオプション - -Wredundant-decls

-Wredundant-decls
同一スコープ内で宣言が2回以上さているものがある場合に警告を出力

テスト概要

オプション無し、および-Wredundant-declsオプションを使用した際の警告出力例

実行環境

GCC-8.2.0
GNU C Library 2.28
GNU Binutils 2.31.1


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

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

使用ファイル


sample.c
#include <stdio.h> void sampFunc(); void sampFunc(); gcc sample.c/* 重複宣言 */ void sampFunc() { } int main(void) { sampFunc(); return 0; }

動作テスト

オプション無しでコンパイルを実行
$ gcc sample.c 警告無し $

-Wredundant-declsオプション使用してコンパイルを実行
$ gcc -Wredundant-decls sample.c sample.c:4:6: warning: redundant redeclaration of ‘sampFunc’ [-Wredundant-decls] void sampFunc(); /* 重複宣言 */ ^~~~~~~~ sample.c:3:6: note: previous declaration of ‘sampFunc’ was here void sampFunc(); ^~~~~~~~ $ 「sampFunc」の再宣言についての警告