Do not use flexible member arrays in C++.

This is supported as compiler extensions, but we can be standards
compliant here, so use the classic workaround of having a single entry
array at the end of the structs instead.
This commit is contained in:
Hans-Kristian Arntzen 2016-05-23 09:15:49 +02:00
parent e717daee76
commit 78e7615af6
3 changed files with 14 additions and 0 deletions

View File

@ -251,6 +251,7 @@ string CompilerCPP::compile()
backend.basic_uint_type = "uint32_t";
backend.swizzle_is_function = true;
backend.shared_is_implied = true;
backend.flexible_member_array_supported = false;
uint32_t pass_count = 0;
do

View File

@ -3735,7 +3735,19 @@ string CompilerGLSL::type_to_array_glsl(const SPIRType &type)
{
res += "[";
if (size)
{
res += convert_to_string(size);
}
else if (!backend.flexible_member_array_supported)
{
// For runtime-sized arrays, we can work around
// lack of standard support for this by simply having
// a single element array.
//
// Runtime length arrays must always be the last element
// in an interface block.
res += '1';
}
res += "]";
}
return res;

View File

@ -203,6 +203,7 @@ protected:
const char *basic_uint_type = "uint";
bool swizzle_is_function = false;
bool shared_is_implied = false;
bool flexible_member_array_supported = true;
} backend;
void emit_struct(const SPIRType &type);