www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - duplicate union initialization

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


# class C{
#     void dummy(){
#     }
#
#     union{
#         int[] x = [1, 3];
#         struct{
#             int a;
#             int b;
#         }
#     }
# }
#
# import std.stdio;
# int main(){
#     C c = new C();
#     writefln("[%s, %s] = %s, %s", c.x[0], c.x[1], c.a, c.b);
#     return 0;
# }

The code above behaves as expected, but if the position of x and the
anonymous struct are exchanged:

# class C{ // line 1
#     void dummy(){
#     }
#
#     union{ 
#         struct{
#             int a; // line 7
#             int b;
#         }
#         int[] x = [1, 3]; // line 10 
#     }
# }

a.d(1): class a.C 2duplicate union initialization for x

* I'd expect line 10 and 7 to be mentionted in the error message, not
line 1.

* The "2" in "2duplicate" seems to be a remainder of some debug
logging.

* Is it a bug, or an omission from the docs? Maybe the test case below
is more suitable for discussion:

# class C{
#     union{
#         struct{
#             int a = 1;
#             int b;
#         }
#         struct{
#             int c;
#             int d = 2;
#         }
#     }
# }

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFD86Lq3w+/yD4P9tIRAtseAJ4iHZQ3yzmxBXvGziGdUxFjDSaGkQCgxZW4
PeLeg6Vh4pCVK3gYi9MXhVs=
=9WVu
-----END PGP SIGNATURE-----
Feb 15 2006