Bug 44106

Summary: False warning: 'control reaches end of non-void function' when comparing to undefined var
Product: gcc Reporter: Jeff Donner <jeffrey.donner>
Component: middle-endAssignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: minor CC: gcc-bugs, proljc, sjames
Priority: P3 Keywords: diagnostic
Version: 4.6.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: 4.1.2, 4.3.2 Last reconfirmed: 2021-08-10 00:00:00

Description Jeff Donner 2010-05-13 04:56:41 UTC
int f(int i)
{
   if (i == undefined_var) {
      return 1;
   }
   else {
      return 0;
   }
}

/usr/local/gcc-svn/bin/g++ -Wall -Wextra -c bad-return.cpp
bad-return.cpp: In function ‘int f(int)’:
bad-return.cpp:3:13: error: ‘undefined_var’ was not declared in this scope
bad-return.cpp:9:1: warning: control reaches end of non-void function [-Wreturn-type]

Happens as .c and gcc, and as .cpp with g++. The warning does not occur in 4.4.3. Untried with 4.5.x.
Comment 1 Jeff Donner 2010-05-14 02:23:03 UTC
Occurs in GCC 4.5.1 also. 
Comment 2 Andrew Pinski 2010-07-24 21:26:19 UTC
>The warning does not occur in 4.4.3.

For C, it does.  And it warns in 4.1.2 also.

Confirmed.