Consider the following code:
struct A{
int x;
int y;
};
struct B{
int y;
int x;
};
void func (A){
}
void func (B){
}
int main()
{
func({.y=1,.x=1});
}
For some reason both clang and gcc consider this code ambiguous even though it is known that order in designated initializer must match the order in struct, although for some reason clang allows it and just issues a warning:
ISO C++ requires field designators to be specified in declaration order; field 'y' will be initialized after field 'x' [-Wreorder-init-list]
Now the fun begins:
If I comment out the func(B)
code goes from ambiguous to not compiling.
That is what I consider super weird. Is there some logic behind this?
If the cause of my confusion is not clear:
if we have both func(A)
and func(B)
in code both gcc and clang consider the func({.y=1,.x=1})
ambiguous, but if I remove func(B)
from source then it gives an error(or warning in case of clang). In other words we went from 2 options to 0 options by removing 1 option.