Bug 5284

Summary: missing warning on uninitialized variable if used within a ternary expression (?:)
Product: gcc Reporter: peter.barth
Component: c++Assignee: Andrew Pinski <pinskia>
Status: RESOLVED DUPLICATE    
Severity: normal CC: gcc-bugs, giovannibajo, nathan
Priority: P3 Keywords: diagnostic
Version: 3.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2003-08-02 17:52:06

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 ***