D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11305 - Operations with array length cannot be used as a condition
Summary: Operations with array length cannot be used as a condition
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 minor
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2013-10-20 04:56 UTC by Denis Shelomovskii
Modified: 2023-02-11 05:40 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Denis Shelomovskii 2013-10-20 04:56:05 UTC
As a result of compiler rewrite we get this:
---
void main()
{
    int[] arr;
    if(++arr.length) { } // Error: assignment cannot be used as a condition, perhaps == was meant?
}
---
Comment 1 basile-z 2019-06-30 07:59:12 UTC
This is because the preincrement expression is lowered.

   ++arr.length

is rewritten

    arr.length = arr.length + 1LU

which  is not allowed as IfCondition, to prevent the "=" vs "==" error.
Comment 2 basile-z 2023-02-11 05:40:10 UTC
works since 2.088