Bug 5284 - missing warning on uninitialized variable if used within a ternary expression (?:)
Summary: missing warning on uninitialized variable if used within a ternary expression...
Status: RESOLVED DUPLICATE of bug 10538
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.0
: P3 normal
Target Milestone: ---
Assignee: Andrew Pinski
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2002-01-05 01:36 UTC by peter.barth
Modified: 2003-08-17 22:57 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-08-02 17:52:06


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description peter.barth 2002-01-05 01:36:00 UTC
GCC should issue a warning on
           int j = (j < 0) ? -i : i;
that j is used uninitialized (some other compilers do).
Complete code snippet
---
#include <iostream>
using namespace std;

int f(int i) 
{
  int j = (j < 0) ? -i : i; // shouldn't that generate a warning that j is used uninitialized
  return j;
}

int main()
{
  int h = 3;
  cout << h << " " << f(h) << "\n";
  h = -3;
  cout << h << " " << f(h) << "\n";
  return 0;
}
---

Release:
gcc-2.95.3, gcc-3.0

Environment:
SuSe Linux 7.3

How-To-Repeat:
#include <iostream>
using namespace std;

int f(int i) 
{
  int j = (j < 0) ? -i : i; // shouldn't that generate a warning that j is used uninitialized
  return j;
}

int main()
{
  int h = 3;
  cout << h << " " << f(h) << "\n";
  h = -3;
  cout << h << " " << f(h) << "\n";
  return 0;
}
Comment 1 peter.barth 2002-01-05 01:36:00 UTC
Fix:
???
Comment 2 Nathan Sidwell 2002-09-15 12:26:57 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: confirmed. No warning at -W -Wall -O2
Comment 3 Giovanni Bajo 2003-05-09 19:02:15 UTC
Responsible-Changed-From-To: unassigned->gdr
Responsible-Changed-Why: Diagnostic mantainer
Comment 4 Andrew Pinski 2003-08-02 17:52:06 UTC
Another `int j=j;' warning problems.
Comment 5 Andrew Pinski 2003-08-07 04:23:47 UTC
I am working on a patch.
Comment 6 Andrew Pinski 2003-08-17 22:57:15 UTC
The bug is cause by the same bug in PR 10538 so closing as a dup.  I have already submitted a 
patch.

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