Type qualifiers - inout error

Jonathan M Davis jmdavisProg at gmx.com
Fri Jun 17 01:05:50 PDT 2011


On 2011-06-16 16:01, Claudiu Verdes wrote:
> Hi,
> 
> I'm new to D and trying to follow Alexandrescu's TDPL code examples I came
> across an error on the code below:
> 
> class A
> {
> inout(int) val() inout
> {
> return _val; // error - see below
> }
> private int _val;
> };
> 
> The compiler (dmd v2.052) complains on the marked line with the message
> "Error: inout on return means inout must be on a parameter as well for
> inout inout(int)()".
> 
> What am I doing wrong? TDPL has a very similar example...

dmd has no fully implemented everything in TDPL. _Most_ of it has been, but 
not everything. inout is one of the few, major examples of a feature that is 
not fuly implemented yet, and it's essentially unusable at this point: 
http://d.puremagic.com/issues/show_bug.cgi?id=3748

alias this would be the other major feature that I can think of that TDPL 
talks about which doesn't yet quite work as TDPL describes. Unlike inout, 
alias this works (though it is rather buggy in some situations), but TDPL 
claims that you can have multiple alias this's per type, and that's not yet 
true.

So, TDPL is a fantastic book, and it's mostly correct, but it ended up going 
to press before absolutely everything it mentions was fully implemented. If 
you search bugzilla ( d.puremagic.com/issues ) for TDPL, you'll find several 
bugs relating to dmd and TDPL not yet matching. In almost all cases, dmd is 
going to be changed to match TDPL rather than TDPL being ultimately wrong, but 
it does mean that occasionally, what you read in TDPL won't yet work in D.

Official Errata: http://erdani.com/tdpl/errata/index.php?title=Main_Page

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list