Summary: To avoid a problem with Template syntax
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: diagnostic
          Severity: enhancement
          Priority: P2
         Component: DMD

--- Comment #0 from 2010-11-28 15:14:06 PST ---
D has removed some cases of bug-prone C syntax, like:

int main() {
    int* ptr1, ptr2;
    return 0;

But D must avoid introducing new ones. D2 has introduced a handy shortcut to
define templates, but this shortcut must not cause ambiguity for the eyes of
the programmer that reads the code (I don't care if the syntax is perfectly
defined for the D compiler, here I am talking about human users and their
fallible nature. Because the same was true for some C syntax too, that is well
defined for the compiler).

So to avoid troubles this code raises a syntax error, this is good:

struct Foo(T) {}
Foo!Foo!int y;
void main() {}

test.d(2): multiple ! arguments are not allowed

But this D2 code too may be ambiguous for the person that reads it:

struct Foo(T) {}
Foo!int* x;
static assert(!is(typeof(x) == Foo!(int*)));
static assert(is(typeof(x) == Foo!(int)*));
void main() {}

In similar situations I'd like D to require parentheses (so "Foo!int* x;"
becomes a syntax error), so the programmer must write:

And this possible source of confusion for the person that reads the code is

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to