Commit 487b63ab by Olli Etuaho Committed by Commit Bot

Disallow structs as scalar/vector constructor arguments

The spec isn't very explicit about disallowing this, but conversions from structs are not among the conversion constructors or specified in any other way either. BUG=angleproject:2036 TEST=angle_unittests Change-Id: I23f2ceda1d1348cec0d3bba38a7a013275ff84eb Reviewed-on: https://chromium-review.googlesource.com/514002 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 83498433
......@@ -640,6 +640,12 @@ bool TParseContext::checkConstructorArguments(const TSourceLoc &line,
const TIntermTyped *argTyped = arg->getAsTyped();
ASSERT(argTyped != nullptr);
if (argTyped->getBasicType() == EbtStruct)
{
error(line, "a struct cannot be used as a constructor argument for this type",
"constructor");
return false;
}
if (argTyped->getType().isArray())
{
error(line, "constructing from a non-dereferenced array", "constructor");
......@@ -655,7 +661,7 @@ bool TParseContext::checkConstructorArguments(const TSourceLoc &line,
{
overFull = true;
}
if (type.getBasicType() != EbtStruct && !type.isArray() && size >= type.getObjectSize())
if (size >= type.getObjectSize())
{
full = true;
}
......
......@@ -3858,3 +3858,24 @@ TEST_F(FragmentShaderValidationTest, InvalidInterfaceBlockTernaryExpression)
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Test that a struct can not be used as a constructor argument for a scalar.
TEST_F(FragmentShaderValidationTest, StructAsBoolConstructorArgument)
{
const std::string &shaderString =
"precision mediump float;\n"
"struct my_struct\n"
"{\n"
" float f;\n"
"};\n"
"my_struct a = my_struct(1.0);\n"
"void main(void)\n"
"{\n"
" bool test = bool(a);\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment