File tree 2 files changed +26
-1
lines changed
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -2131,7 +2131,15 @@ public:
2131
2131
return ;
2132
2132
}
2133
2133
2134
- if (goal == ctfeNeedLvalue)
2134
+ // Note: This is a workaround for
2135
+ // https://issues.dlang.org/show_bug.cgi?id=17351
2136
+ // The aforementioned bug triggers when passing manifest constant by `ref`.
2137
+ // If there was not a previous reference to them, they are
2138
+ // not cached and trigger a "cannot be read at compile time".
2139
+ // This fix is a crude solution to get it to work. A more proper
2140
+ // approach would be to resolve the forward reference, but that is
2141
+ // much more involved.
2142
+ if (goal == ctfeNeedLvalue && e.var.type.isMutable())
2135
2143
{
2136
2144
VarDeclaration v = e.var.isVarDeclaration();
2137
2145
if (v && ! v.isDataseg() && ! v.isCTFE() && ! istate)
Original file line number Diff line number Diff line change
1
+ bool fun (S)(ref S[3 ] a) { assert (a == [42 , 84 , 169 ]); return true ; }
2
+ bool fun2 (S)(ref S a) { return true ; }
3
+ void main ()
4
+ {
5
+ static const int [3 ] sa = [42 , 84 , 169 ];
6
+ static const double sa2 = 42.42 ;
7
+ static assert (fun(sa));
8
+ static assert (fun2(sa2));
9
+ }
10
+
11
+ int f1 (ref const int p) { return p; }
12
+ int f2 (ref const int [2 ] p) { return p[0 ] + p[1 ]; }
13
+ void test2 ()
14
+ {
15
+ static immutable int [2 ] P = [ 0 , 1 ];
16
+ static assert (f2(P) == 1 );
17
+ }
You can’t perform that action at this time.
0 commit comments