From efb84617222a9b76e029ba7e784f274af8df109d Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Tue, 21 Jul 2015 14:35:39 -0600 Subject: [PATCH] Issue #26: Detect empty array constructors, require at least on operand. --- Test/array.frag | 2 ++ Test/baseResults/array.frag.out | 6 +++++- glslang/MachineIndependent/ParseHelper.cpp | 6 +++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Test/array.frag b/Test/array.frag index 8e3687f88..02c86097c 100644 --- a/Test/array.frag +++ b/Test/array.frag @@ -100,3 +100,5 @@ void foo3() resize2.length(); resize2[5] = 4.0; // ERROR } + +int[] i = int[](); // ERROR, need constructor arguments diff --git a/Test/baseResults/array.frag.out b/Test/baseResults/array.frag.out index 64ed5533e..d48414c15 100644 --- a/Test/baseResults/array.frag.out +++ b/Test/baseResults/array.frag.out @@ -22,7 +22,9 @@ ERROR: 0:79: '' : array size required ERROR: 0:84: 'return' : type does not match, or is not convertible to, the function's return type ERROR: 0:93: 'length' : array must be declared with a size before using this method ERROR: 0:101: '[' : array index out of range '5' -ERROR: 23 compilation errors. No code generated. +ERROR: 0:104: 'constructor' : array constructor must have at least one argument +ERROR: 0:104: '=' : cannot convert from 'const float' to 'global implicitly-sized array of int' +ERROR: 25 compilation errors. No code generated. Shader version: 130 @@ -264,6 +266,7 @@ ERROR: node is still EOpNull! 0:? 'guns' (global implicitly-sized array of 3-component vector of float) 0:? 'f' (global float) 0:? 'gUnusedUnsized' (global implicitly-sized array of float) +0:? 'i' (global implicitly-sized array of int) Linked fragment stage: @@ -508,4 +511,5 @@ ERROR: node is still EOpNull! 0:? 'guns' (global 8-element array of 3-component vector of float) 0:? 'f' (global float) 0:? 'gUnusedUnsized' (global 1-element array of float) +0:? 'i' (global 1-element array of int) diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index 25d129a10..b993ee0d7 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -1973,6 +1973,10 @@ bool TParseContext::constructorError(TSourceLoc loc, TIntermNode* node, TFunctio type.getQualifier().storage = EvqConst; if (type.isArray()) { + if (function.getParamCount() == 0) { + error(loc, "array constructor must have at least one argument", "constructor", ""); + return true; + } if (type.isImplicitlySizedArray()) { // auto adapt the constructor type to the number of arguments type.changeArraySize(function.getParamCount()); @@ -1992,7 +1996,7 @@ bool TParseContext::constructorError(TSourceLoc loc, TIntermNode* node, TFunctio // "If a matrix argument is given to a matrix constructor, // it is a compile-time error to have any other arguments." - if (function.getParamCount() > 1) + if (function.getParamCount() != 1) error(loc, "matrix constructed from matrix can only have one argument", "constructor", ""); return false; }