GNOME Bugzilla – Bug 678791
Comparison of an enum with a nullable enum
Last modified: 2014-06-30 13:42:26 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_)) { // ...
b == a works. Fun :/
Created attachment 279541 [details] [review] Fix comparsion of nullable value types
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.