D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6750 - Explicit template instantiation with auto ref
Summary: Explicit template instantiation with auto ref
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2011-09-30 18:51 UTC by marcianx
Modified: 2014-11-06 01:41 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description marcianx 2011-09-30 18:51:55 UTC
I tried this on the DMD64 D compiler v2.055 on linux. The valid D code at the
bottom fails with the following errors when I invoke
----------
$ dmd template_autoref_bug.d
template_autoref_bug.d(3): Error: auto can only be used for template function parameters
----------
I found three independent ways to suppress this bug (mentioned also in the
comments below).
1. I introduce line A.
2. Replace "auto ref" with "const ref".
3. Add a dummy template parameter with default value to the signature of
   mat_mult_ret() as mentioned in the code comments.
The fact that the above workarounds actually work seems to indicate that
it is not an error in my understanding of "auto ref", but an actual bug.

----------
struct MatrixT(int M, int N) { }

void mat_mult_ret(int M,int N,int P)(
    auto ref MatrixT!(M,N) A, 
    auto ref MatrixT!(N,P) B,
    ref MatrixT!(M,P) ret)
{
}

void main(string[] args)
{
    MatrixT!(2,2) mat22;
    MatrixT!(3,2) mat32;
    MatrixT!(2,3) mat23;

    // Line B by itself => compiler says:
    //    template_autoref_bug.d(3): Error: auto can only be used for
    //    template function parameters

    // To suppress bug (any one works):
    // * Lines A and B together => no error
    // * Line A by itself => no error
    // * Replace "auto ref" with "const ref"
    // * Add dummy parameter to signature of function:
    //     void mat_mult_ret(int M,int N,int P, dum=void)(...) {...}

    //mat_mult_ret(mat23, mat32, mat22); // line A
    mat_mult_ret!(2,3,2)(mat23, mat32, mat22); // line B
}
----------
Comment 1 hsteoh 2014-11-06 01:41:25 UTC
Tested on dmd git HEAD, Linux/64, the compiler now accepts this code (including various variations as suggested in the comments). Looks like it's fixed since. Please reopen the bug if the problem still occurs. Thanks!