Code similar to the one below does not give a warning (though one is expected).
int foo()
{
int x = x;
return x;
}
Though this code in itself seems stupid - this is how it hid into my codebase
(in a simplified example).
#include
#define macro2(imm) \
do {\
int __value = (imm);\
printf("macro2 got %d\n", __value);\
}while(0)
#define macro3(imm) \
do { \
int __value = (imm);\
printf("macro3 got %d\n", __value);\
} while(0);
#define macro1(imm)\
do {\
int __value = (imm);\
printf("macro1 got %d\n", __value);\
macro2(__value);\
macro3(__value);\
}while(0)
int foobar()
{
printf("foobar was called\n");
return 42;
}
int main()
{
macro1(foobar());
return 0;
}
The expected output was
"""
foobar was called
macro1 got 42
macro2 got 42
macro3 got 42
"""
But I get
"""
[EMAIL PROTECTED] samples $ gcc -Wall -pedantic -ansi -O3 test.c
[EMAIL PROTECTED] samples $ ./a.out
foobar was called
macro1 got 42
macro2 got 805441120
macro3 got 805441120
"""
The original code was spread accross 4 files. I think the code
should generate a valid warning because the variable is as good
as being stack/register junk .
Tested with "gcc (GCC) 3.4.1 20040803 (Gentoo Linux 3.4.1-r3, ssp-3.4-2,
pie-8.7.6.5)".
--
Summary: No warning for uninitialized local variable use
Product: gcc
Version: 3.4.1
Status: UNCONFIRMED
Severity: minor
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gopalv82 at dotgnu dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: powerpc-unknown-linux-gnu
GCC host triplet: powerpc-unknown-linux-gnu
GCC target triplet: powerpc-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19099