www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8433] New: Compiler could warn on duplicate static if checks which can't branch

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8433

           Summary: Compiler could warn on duplicate static if checks
                    which can't branch
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com



06:38:22 PDT ---
void main()
{
    enum int x = 1;

    static if (x == 1)
    {
        writeln("1");
    }
    else
    static if (x == 1)
    {
        writeln("2");
    }
}

Only the first write statement will be compiled in. I think the compiler could
help in these cases and produce a warning. There could be more complicated
cases like:

    static if (x != 1)
    {
    }
    else
    static if (x == 2)
    {
    }

Here again the second branch is never compiled.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 25 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8433


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com



10:51:40 PDT ---
The trouble with a language feature like this is defining it. You'd have to
enumerate the cases that are detected and the cases that are not, which has the
side effect of prohibiting improving it. You don't really want a situation
where code compiles with one compiler and does not with another, even with both
being standard conforming.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 25 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8433




11:12:27 PDT ---
I'd like to just keep this in Bugzilla for the time being. I know it's
problematic and might even slow down compilation considerably, so maybe it's
best to just discuss about it sometime. It could be a nice feature to have if
you rely on compile-time branching a lot.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 25 2012