Reputation: 4337
I'm reading the GLSL specification and noticed in chapter 9 in the grammar section that declarations can consist of only type qualifiers. Which leads me to believe that the specification allows declarations such as this:
const;
const a;
const a, b;
But this appears as a syntax error when I check it with glslangValidator:
test.vert
ERROR: 0:1: 'a' : identifier not previously declared
ERROR: 1 compilation errors. No code generated.
Are these kinds of declarations suppose to be valid? Was it suppose to be "type_specifier" instead of "type_qualifier" and this is just a mistake?
Here are the relevant bits from the specification:
invariant_qualifier :
INVARIANT
interpolation_qualifier :
SMOOTH
FLAT
NOPERSPECTIVE
layout_qualifier :
LAYOUT LEFT_PAREN layout_qualifier_id_list RIGHT_PAREN
layout_qualifier_id_list :
layout_qualifier_id
layout_qualifier_id_list COMMA layout_qualifier_id
layout_qualifier_id :
IDENTIFIER
IDENTIFIER EQUAL constant_expression
SHARED
storage_qualifier :
CONST
IN
OUT
INOUT
CENTROID
PATCH
SAMPLE
UNIFORM
BUFFER
SHARED
COHERENT
VOLATILE
RESTRICT
READONLY
WRITEONLY
SUBROUTINE
SUBROUTINE LEFT_PAREN type_name_list RIGHT_PAREN
precise_qualifier :
PRECISE
type_qualifier :
single_type_qualifier
type_qualifier single_type_qualifier
single_type_qualifier :
storage_qualifier
layout_qualifier
precision_qualifier
interpolation_qualifier
invariant_qualifier
precise_qualifier
declaration :
function_prototype SEMICOLON
init_declarator_list SEMICOLON
PRECISION precision_qualifier type_specifier SEMICOLON
type_qualifier IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE SEMICOLON
type_qualifier IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE IDENTIFIER SEMICOLON
type_qualifier IDENTIFIER LEFT_BRACE struct_declaration_list RIGHT_BRACE IDENTIFIER array_specifier SEMICOLON
type_qualifier SEMICOLON
type_qualifier IDENTIFIER SEMICOLON
type_qualifier IDENTIFIER identifier_list SEMICOLON
Here is a link to the full specification.
Upvotes: 2
Views: 245
Reputation: 473202
A language is more than just its grammatical structure. You can write a sentence that conforms to the rules of English grammar, yet it doesn't actually make any kind of sense.
The same goes here. It is grammatically legal to use just a type-qualifier. But that doesn't mean it is semantically valid to do so with every type-qualifier. Or even most of them.
So the declaration:
const;
Is not semantically meaningful, despite being grammatically legal.
Note that type-qualifier
permits a sequence of qualifiers. And note that among the qualifiers are the storage-qualifiers in
, out
, uniform
and buffer
.
By allowing type-qualifier SEMICOLON
, the standard permits this kind of grammar:
layout(std140) uniform;
This is valid both grammatically and in terms of meaning. It sets the default layout for all uniform blocks following this statement to std140
.
Upvotes: 1