Bug 4266 - Pointless compiler warning
Pointless compiler warning
Status: RESOLVED WONTFIX
Product: AMX Mod X
Classification: Unclassified
Component: Core
trunk
PC All
: P3 normal
Assigned To: amxmodx-bugs@alliedmods.net
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-02-04 16:32 PST by vilaemail
Modified: 2013-07-04 13:29 PDT (History)
3 users (show)

See Also:


Attachments

Description vilaemail 2010-02-04 16:32:11 PST
Hi,

since I could not find Compiler 'Component' I put it to Core. Please do move it if I made a mistake. To the point:

AMXX compiler should be more "smarter".

This code returns compile warning:
Code:

if(someBoolVar) {
        return PLUGIN_CONTINUE
    } else {
        return PLUGIN_HANDLED
    }

Warning:
warning 209: Function "someFunction" should return a value.

As you see function returns value depending on branch. So compiler should check if both branches return value and conclude based on that should or should not return a warning.

Thanks for reading.
Comment 1 vilaemail 2010-02-04 16:33:55 PST
Additionally if one or more branches don't return a value it should raise "Function ... doesn't return value on every branch" warning.
Comment 2 David Anderson [:dvander] 2010-02-04 17:04:19 PST
Could you give a better description of the semantics in comment #1? Any solution that breaks existing code is not good - and taken strictly, it seems like it would break this:

I don't understand comment #1 - it seems like it would break this perfectly valid, existing code:

 f() {
   if (expression)
     return 1
   else
     g()
   return 1
 }

Even missing the "return 1", this is valid code, since Pawn's semantics have an implicit "return 0" (not saying I agree with this, however - I think it already warns).
Comment 3 vilaemail 2010-02-04 17:23:27 PST
Code is:

f()
{
  if(something)
      return 1
  else
      return 2
}

Warning is that function f should return a value. Function returns value in one of if branches. Clearer?

Note You need to log in before you can comment on or make changes to this bug.