Bug 2561 – Function return values cannot be used as "ref const" parameters
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-01-07T04:12:00Z
Last change time
2015-06-09T01:21:01Z
Assigned to
bugzilla
Creator
sludwig
Comments
Comment #0 by sludwig — 2009-01-07T04:12:36Z
It seems that POD types cannot be directly used as "ref const" parameters when returned from a function. Only direct struct initializers work - if those can be considered as a function call. However, when using -inline and the called function is inlined, the code works as expected.
The following code snippet will crash the compiler with:
Internal error: ..\ztc\cod4.c 357
---
struct S {}
S x(){ return S(); }
void f(ref const S){}
void g(){ f(x()); }
---
When using a primitive data type, an error is generated instead:
?.d(4): function sxg.metrics.f (ref const const(int) _param_0) does not match parameter types (int)
?.d(4): Error: x() is not an lvalue
---
alias int S;
S x(){ return 0; }
void f(ref const S){}
void g(){ f(x()); }
---
Comment #1 by sludwig — 2009-01-07T04:16:32Z
Touches the same issue as the previous bug report #2560
*** This bug has been marked as a duplicate of 2560 ***