code-d
code-d copied to clipboard
Incorrect static literal hint in structs with unions.
Example code:
module app;
struct A{
int a;
union{
int b;
int c;
}
}
void main(string[] args) {
//A a = A()
}
Writing the A(
part in the main provides a hint for the constructor, but this does not display a
:
~~I would assume 'overrides' would be the way to display this.
The number of overrides could however grow exponentially in an overly complex case, as each union member introduces n
new overrides, where n
is the number of overrides without the specific union considered (1
in this simple example)
A struct with 3 separate unions, each with 2 entries, would for example introduce 8 different constructors.~~
According to documentation, struct literals should only refer to the first elements of anonymous unions.
The constructor should thus instead display this(int a, int b)
in this example. this()
and this(int a)
might however also be viable 'overrides'.