[Mesa-dev] [PATCH] glsl: empty declarations should be valid
Chad Versace
chad at chad-versace.us
Fri Aug 5 12:37:43 PDT 2011
On 08/05/2011 11:45 AM, Paul Berry wrote:
> On 4 August 2011 18:18, Chad Versace <chad at chad-versace.us> wrote:
>> On 08/04/2011 01:29 PM, Eric Anholt wrote:
>>> On Thu, 4 Aug 2011 12:59:35 +0900, Chia-I Wu <olvaffe at gmail.com> wrote:
>>>> From: Chia-I Wu <olv at lunarg.com>
>>>>
>>>> Unlike C++, empty declarations such as
>>>>
>>>> float;
>>>>
>>>> should be valid. The spec is not explicit about this actually.
>>>>
>>>> Some apps that generate their shader sources may rely on this. This was
>>>> noted when porting one of them to Linux from Windows.
>>>
>>> Ew. Looking the GLSL 1.20 spec, I see:
>>>
>>> statement:
>>> declaration_statement
>>>
>>> declaration_statement:
>>> declaration
>>>
>>> declaration:
>>> init_declarator_list SEMICOLON
>>>
>>> init_declarator_list:
>>> single_declaration
>>>
>>> single_declaration:
>>> fully_specified_type
>>> fully_specified_type IDENTIFIER
>>>
>>> so it looks like that is actually valid code. That's awful.
>>
>> I first suspected that this was a spec grammar bug. But it is still present in
>> the GLSL 4.10 spec, so it's unlikely to be a bug.
>>
>> Surprisingly, C also allows empty declarations. Compiling this
>> float;
>> int main() { return 0; }
>> with `gcc --std=c99` succeeds and emits this warning:
>> warning: useless type name in empty declaration [enabled by default]
>>
>> I hate to say this, but I believe the spec grammar intentionally allows empty
>> declarations. C allows it, and GLSL tries to mimic C.
>>
>> Even though I don't like empty declarations, this patch is
>> Reviewed-by: Chad Versace <chad at chad-versace.us>
>>
>> --
>> Chad Versace
>> chad at chad-versace.us
>>
>>
>> _______________________________________________
>> mesa-dev mailing list
>> mesa-dev at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>>
>>
>
> Anyone want to volunteer to write a Piglit test for this? It seems
> like the kind of obscure corner case that we're likely to regress on
> if we don't explicitly test for it.
Tests are posted on the Piglit list.
--
Chad Versace
chad at chad-versace.us
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 900 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20110805/9aa6c5fb/attachment.pgp>
More information about the mesa-dev
mailing list