UDAs grammar: @<template_instance> valid?

Kenji Hara via Digitalmars-d digitalmars-d at puremagic.com
Wed Oct 29 06:21:32 PDT 2014


2014-10-29 21:33 GMT+09:00 Bruno Medeiros via Digitalmars-d <
digitalmars-d at puremagic.com>:

> Someone opened an issue report for a bug in the DDT parser, it doesn't
> parse this:
>
> template X(int Y){}
>
> @X!3  // error here
> void main(){}
>
> And yet DMD accepts this code. Is this grammar supposed to be valid
> though? The grammar spec doesn't allow it, not that means much. I searched
> for an open grammar bug, but couldn't find one.


It is a grammar bug, because DMD parser intentionally accepts the syntax.

https://github.com/D-Programming-Language/dmd/blob/9d1d0245fda3107f01d2b1460c7bcc34188a751e/src/parse.c#L1003

StorageClass Parser::parseAttribute(Expressions **pudas)
{
    nextToken();
    Expressions *udas = NULL;
    StorageClass stc = 0;
    if (token.value == TOKidentifier)
    {
        if (token.ident == Id::property)
            ...
        else
        {
            // Allow identifier, template instantiation, or function call
<-----
            Expression *exp = parsePrimaryExp();
            if (token.value == TOKlparen)
            {
                Loc loc = token.loc;
                exp = new CallExp(loc, exp, parseArguments());
            }

            udas = new Expressions();
            udas->push(exp);
        }
    }

Kenji Hara
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20141029/333ad9cc/attachment.html>


More information about the Digitalmars-d mailing list