Bug 45493 - -Wuninitialized does not warn
Summary: -Wuninitialized does not warn
Status: RESOLVED DUPLICATE of bug 18501
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.4.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-02 03:40 UTC by Tad Hunt
Modified: 2010-09-02 22:50 UTC (History)
18 users (show)

See Also:
Host: x86_64-linux-gnu
Target: x86_64-linux-gnu
Build: x86_64-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tad Hunt 2010-09-02 03:40:47 UTC
When the first use of an uninitialized variable is inside a loop, no warning is generated when -Wuninitialized is turned on.

int
main(void)
{
	int len, i;

	for(i = 0; i < 5; i++) {
		printf("%d\n", len);		// no warning!
		len = 10;
	}

	return 0;
}
Comment 1 Tad Hunt 2010-09-02 03:42:23 UTC
Same behavior on 4.4.3 & 4.4.1 (same host, target & build)

Forgot to mention:

gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) 
gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9) 
Comment 2 Richard Biener 2010-09-02 09:12:02 UTC
It's just optimized to always print 10 and the maybe-uninitialized warning
code runs too late.

A dup of some other PR.
Comment 3 Tad Hunt 2010-09-02 16:08:20 UTC
(In reply to comment #2)

Richard, thanks for the confirmation.

This is a great feature that we've come to rely on over the years for catching rookie errors.

This might not appear in comments very often, but I appreciate the hard work you and the rest of the gcc folks put in.
Comment 4 Manuel López-Ibáñez 2010-09-02 22:50:48 UTC
CCP is responsible for this.

*** This bug has been marked as a duplicate of 18501 ***