[Issue 5889] New: Struct construction should be rvalue

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 26 00:35:02 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5889

           Summary: Struct construction should be rvalue
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: k.hara.pg at gmail.com


--- Comment #0 from Kenji Hara <k.hara.pg at gmail.com> 2011-04-26 00:31:19 PDT ---
This issue is combined issue 5178 and 5769, etc.

Following code should be passed.
----
struct S1{  }
struct S2{ int n; }
struct S3{ this(int n){} }

struct X1(T){  }
struct X2(T){ int n; }
struct X3(T){ this(int n){} }

bool isRvalue(T)(auto ref T t){ return !__traits(isRef, t); }
template Fn(string code){ mixin(code); }

void main()
{
    // 1.
    assert(isRvalue(S1(  )));       // now false, expect true
    assert(isRvalue(S2(12)));       // now false, expect true
    assert(isRvalue(S3(13)));       // now false, expect true

    // 2.
    static assert(!__traits(compiles, Fn!`ref S1 get1(){return S1(  );}`));    
        // now OK, expect NG
    static assert(!__traits(compiles, Fn!`ref S2 get2(){return S2(22);}`));    
        // now OK, expect NG
    static assert(!__traits(compiles, Fn!`ref S3 get3(){return S3(23);}`));    
        // now OK, expect NG

    static assert(!__traits(compiles, Fn!`ref X1!int get(){ return X1!int(  );
}`));    // now OK, expect NG
    static assert(!__traits(compiles, Fn!`ref X2!int get(){ return X2!int(32);
}`));    // now OK, expect NG
    static assert(!__traits(compiles, Fn!`ref X3!int get(){ return X3!int(33);
}`));    // now OK, expect NG

    // 3.
    void getref(T)(ref T t){}
    static assert(!__traits(compiles, getref(S1(  ))));         // now OK,
expect NG
    static assert(!__traits(compiles, getref(S2(42))));         // now OK,
expect NG
    static assert(!__traits(compiles, getref(S3(43))));         // now OK,
expect NG

    static assert(!__traits(compiles, getref(X1!int(  ))));     // now OK,
expect NG
    static assert(!__traits(compiles, getref(X2!int(10))));     // now OK,
expect NG
    static assert(!__traits(compiles, getref(X3!int(10))));     // now OK,
expect NG

    void getrefS1(ref S1 t){}
    void getrefS2(ref S2 t){}
    void getrefS3(ref S3 t){}
    static assert(!__traits(compiles, getrefS1(S1(  ))));       // now OK,
expect NG
    static assert(!__traits(compiles, getrefS2(S2(10))));       // now OK,
expect NG
    static assert(!__traits(compiles, getrefS3(S3(10))));       // now OK,
expect NG

    void getrefX1(ref X1!int t){}
    void getrefX2(ref X2!int t){}
    void getrefX3(ref X3!int t){}
    static assert(!__traits(compiles, getrefX1(X1!int(  ))));   // now OK,
expect NG
    static assert(!__traits(compiles, getrefX2(X2!int(10))));   // now OK,
expect NG
    static assert(!__traits(compiles, getrefX3(X3!int(10))));   // now OK,
expect NG
}
----

1. struct literal/construction should make rvalue.
2. returning struct literal/construction ref is invalid.
3. implicit conversion struct literal/construction to lvalue is invalid.
   (At least on ref parameter.)

My patch is here:
https://github.com/9rnsr/dmd/tree/rvalue-struct-literal

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list