www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6005] New: Type alias - variable name don't clash


           Summary: Type alias - variable name don't clash
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: diagnostic
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc

This is D code adapted from a blog post about C language:


Three little D2 programs that compile with no errors. Similar code is allowed
in C too:


alias int Foo;
void foo() {
    Foo bar;
    float Foo;
void main() {}


alias int Foo;
void foo() {
    Foo Foo;
    int bar = Foo + 2;
    assert (bar == 2);
void main() {}


alias char Foo;
void foo() {
    int bar = Foo.sizeof, Foo, spam = Foo.sizeof;
    assert(bar == 1);
    assert(spam == 4);
void main() {}


Is it OK to keep allowing such kind of code in D2 too? Or is it better to
statically forbid it?

A disadvantage of statically disallowing it is the breakage of some valid C
code. On the other hand I don't want to find code like that in D programs.

Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 15 2011