[Issue 10862] New: Assignment inside if condition still sometimes accepted

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 20 14:40:38 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10862

           Summary: Assignment inside if condition still sometimes
                    accepted
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: andrei at erdani.com


--- Comment #0 from Andrei Alexandrescu <andrei at erdani.com> 2013-08-20 14:40:37 PDT ---
Consider:

void main() {
    int a, b;
    if (a = b) {}
}

./test.d(4): Error: assignment cannot be used as a condition, perhaps == was
meant?

Nice! Now consider: 

void main() {
    int a, b;
    if ((a = b) = 0) {}
}

This compiles diagnostic-free. The shape if (expr1 = expr2) should be
disallowed at a grammatical level, i.e. during parsing.

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


More information about the Digitalmars-d-bugs mailing list