Thread overview
[Issue 8433] New: Compiler could warn on duplicate static if checks which can't branch
Jul 25, 2012
Andrej Mitrovic
[Issue 8433] Compiler could warn on static if checks which can't branch
Jul 25, 2012
Walter Bright
Jul 25, 2012
Andrej Mitrovic
July 25, 2012
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


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-07-25 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: -------
July 25, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8433


Walter Bright <bugzilla@digitalmars.com> changed:

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


--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> 2012-07-25 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: -------
July 25, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8433



--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-07-25 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: -------