After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 678791 - Comparison of an enum with a nullable enum
Comparison of an enum with a nullable enum
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Code Generator
0.17.x
Other Linux
: Urgent critical
: ---
Assigned To: Vala maintainers
Vala maintainers
invalid-c-code
Depends on:
Blocks:
 
 
Reported: 2012-06-25 13:42 UTC by Sébastien Wilmet
Modified: 2014-06-30 13:42 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix comparsion of nullable value types (2.15 KB, patch)
2014-06-29 15:46 UTC, Simon Werbeck
none Details | Review

Description Sébastien Wilmet 2012-06-25 13:42:32 UTC
Here is the problem:

enum MyEnum { ONE, TWO }

int main(string[] args)
{
    MyEnum a = MyEnum.ONE;
    MyEnum? b = MyEnum.ONE;

    if (a == b)
        stdout.printf("OK\n");
    else
        stdout.printf("KO\n");

    return 0;
}

If 'a' and 'b' are of type "int" and "int?", respectively, the comparison works as expected and the program prints "OK".

However, the above program prints "KO". During the compilation, gcc reports this warning:
> warning: comparison between pointer and integer

Here is the relevant C code generated:

MyEnum a;
MyEnum* b;
MyEnum _tmp2_;
MyEnum* _tmp3_;
// ...
_tmp2_ = a;
_tmp3_ = b;
if ((&_tmp2_) == (*_tmp3_)) {
// ...
Comment 1 Evan Nemerson 2014-06-27 03:15:11 UTC
b == a works.  Fun :/
Comment 2 Simon Werbeck 2014-06-29 15:46:36 UTC
Created attachment 279541 [details] [review]
Fix comparsion of nullable value types
Comment 3 Luca Bruno 2014-06-30 13:42:26 UTC
commit 61d372c3d65f7830a17ac8aa34b1eb2269b311a7
Author: Simon Werbeck <simon.werbeck@gmail.com>
Date:   Sun Jun 29 17:00:37 2014 +0200

    Fix comparison of nullable value types
    
    Fixes bug 678791

This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.