As long as there's outstanding criticism, I'll add a couple of extra notes:
On 5/3/22 04:57, Giovanni Mascellani wrote:
+[pixel shader fail] +// Implicit size array as function return type +// Note: explicit size arrays are not allowed either. +float4[] merge(float4 a, float4 b) +{
- float4 ret[2];
- ret[0] = a;
- ret[1] = b;
- return ret;
+} +float4 main() : sv_target +{
- float4 a = float4(1, 2, 3, 4);
- float4 b = float4(5, 6, 7, 8);
- return merge(a, b)[0];
+}
Out of scope of this patch perhaps, but that'd be another good thing to add explicit tests for. Frankly, if we had tests for explicitly sized arrays as function return types, I'd say that tests for implicitly sized arrays are superfluous.
As a side note, it's not necessarily obvious that that's the right place to put the brackets. In C, for example, the "right" place is after the close paren (it's still illegal, but it at least parses). It turns out that HLSL doesn't accept them anywhere.
+[pixel shader fail] +// Implicit size array as a typedef +float4 main() : sv_target +{
- float2 arr1[4] = {1, 2, 3, 4, 5, 6, 7, 8};
- float4 arr2[2] = (float2 []) arr1;
- return arr2[1];
+}
As Giovanni pointed out, that's a cast, not a typedef. Adding one for a typedef would be welcome, though :-)
+[pixel shader fail] +// Implicit array of elements of size 0 with broadcast initialization +struct emp { +};
+float4 main() : sv_target +{
- struct emp p[] = 42;
- return float4(1, 2, 3, 4);
+}
Indeed, although it turns out that the offending condition here is actually "initializing an array variable without braces and without an explicit cast", which is rather simpler. More interesting is that
int a[4] = (int[])0;
is invalid.