D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6220 - Regression(2.053) static foreach over a string[] no longer produces directly usable strings
Summary: Regression(2.053) static foreach over a string[] no longer produces directly ...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P3 regression
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2011-06-28 18:43 UTC by Rob Jacques
Modified: 2011-08-13 12:39 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Rob Jacques 2011-06-28 18:43:41 UTC
In DMD 2.052 and prior one could perform a static foreach over static string arrays, such as those produced by traits. However, in DMD 2.053 one has to 'touch' the string before use.

void main(string[] args) {
    struct Foobar { real x; real y; real z;};
    switch("x") {
        foreach(i,member; __traits(allMembers, Foobar)) {
            case member : break; // Valid in 2.052
            //But in DMD 2.053 this produces an error
            //Error: case must be a string or an integral constant, not member

            // Required workaround for DMD 2.053
            //case member[] : break; 
            //case member~"" : break;
        }
    }
}

Also, and I'm not sure if this is a regression or not, if used the pointer of member is not valid i.e. you can not use writeln(member);, etc. Although both i and member.length produce correct results.
Comment 1 Kenji Hara 2011-08-05 15:51:22 UTC
This is regression of Commit:fc67046cf1e66182d959309fb15ef9e2d4c266b9 .

When foreach aggregator is tuple of string literals, the value variable is declared like follows:

  const member = aggregator[i];

And variable member is not const-folded (WANTvalue).
But, before fc67046c, it is interpreted (WANTinterpret), then compile had succeeded.

We should declare value variable as manifest constant there for interpretation.