を使用して非常に奇妙な問題が発生していgcc-4.7 (Ubuntu/Linaro 4.7.2-11precise2) 4.7.2
ます。次の有効なコードを警告なしでコンパイルできません。
extern void dostuff(void);
int test(int arg1, int arg2)
{
int ret;
if (arg1) ret = arg2 ? 1 : 2;
dostuff();
if (arg1) return ret;
return 0;
}
コンパイル オプションと出力:
$ gcc-4.7 -o test.o -c -Os test.c -Wall
test.c: In function ‘test’:
test.c:5:6: warning: ‘ret’ may be used uninitialized in this function [-Wmaybe-uninitialized]
ただし、次のコードは警告なしでコンパイルされます (ただし、アセンブリの効率はわずかに低下します)。
extern void dostuff(void);
int test(int arg1, int arg2)
{
int ret;
if (arg1 && arg2) ret = 1;
if (arg1 && !arg2) ret = 2;
dostuff();
if (arg1) return ret;
return 0;
}
私はいくぶん立ち往生しており、これはコンパイラのバグだと考えています。何かご意見は?