Single return from function with multiple returns [4.4.2]

Is there something that doesn't work right in the latest GZDoom? Post about it here.

Moderator: GZDoom Developers

Forum rules
Please construct and post a simple demo whenever possible for all bug reports. Please provide links to everything.

If you can include a wad demonstrating the problem, please do so. Bug reports that include fully-constructed demos have a much better chance of being investigated in a timely manner than those that don't.

Please make a new topic for every bug. Don't combine multiple bugs into a single topic. Thanks!
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Single return from function with multiple returns [4.4.2]

Post by Apeirogon »

Function with multiple returns, like

Code: Select all

    double, int, bool get_something()
    {
        return 1.1, 15, true;
    }
can be compiled and executed when amount of returned arguments dont match with amount of declared arguments, i.e. this is a valid function for Gzdoom

Code: Select all

    double, int, bool get_something()
    {
        return 1.1;
    }
Example
single_multiple_return_bug.zip
(473 Bytes) Downloaded 48 times
If its intentional design, can it be addressed/make it more clear with warning message on startup like "Warning, <path to file>, <line>: Expected X arguments, but returns only Y"?!
User avatar
Player701
 
 
Posts: 1707
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Single return from function with multiple returns [4.4.2

Post by Player701 »

Sometimes the semantics of a multiple-return function dictate that subsequent return values only make sense when the first return value satisfies a certain condition (non-null, greater than zero etc). In this case, when the other values are meaningless, you can return only the first one, knowing that the subsequent values will not be accessed.

However, with +vm_jit 0, such code triggers an assertion failure in GZDoom. It doesn't make GZDoom crash and only appears in debug builds. I've recently discovered it because my own mod had a similar portion of code where I returned only one value from a method that normally returns two values. It never caused any issues because I didn't use the second value when I knew it wasn't present. Just in case though, I still decided to fix it before I released the next version of the mod.

I guess if you try to use a return value when it isn't there, it is considered "undefined behavior" (oh how I hate that term...) similar to reading from an uninitialized variable. From my experience, if you don't attempt to use it, everything will work fine. Ideally though, I think it'd be better if returning a different number of values wasn't legal at all (could be done with a ZScript version bump) or at least produced a warning at compile time.
Post Reply

Return to “Bugs [GZDoom]”