Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 2019

Show
Ignore:
Timestamp:
09/17/10 23:43:54 (14 years ago)
Author:
dsimcha
Message:

Bug 4882: std.traits hasUnsharedAliasing does not work for function type, plus unlisted bug: interfaces not considered to have indirection, aliasing, etc.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/docsrc/changelog.dd

    r2018 r2019  
    1010        $(UL $(LI  Tuple members are now accessible with the syntax a[0], a[1] etc.) 
    1111             $(LI  Eliminated an internal union. See $(BUGZILLA 4421) and $(BUGZILLA 4846).) 
    1212             $(LI  Worked around $(BUGZILLA 4424). Got opAssign back.) 
    1313             $(LI  Made Tuple.slice!(from, to) to preserve field names if any.) 
    1414             $(LI  Added isTuple!(T) template.) 
    1515        )) 
    1616    ) 
    1717    $(BUGSFIXED 
    1818    $(LI Unlisted bug:  std.exception.pointsTo() calls postblit on subobjects.) 
    1919    $(LI Unlisted bug:  std.typetuple.staticMap!() doesn't work with empty/single tuples.) 
     20    $(LI Unlisted bug:  std.traits:  Interfaces should have indirections, aliasing, etc.) 
     21    $(LI 4882: std.traits hasUnsharedAliasing does not work for function type.) 
    2022    ) 
    2123) 
    2224 
    2325 
    2426<div id=version> 
    2527$(UL 
    2628    $(NEW 049) 
    2729    $(NEW 048) 
    2830    $(NEW 047) 
    2931    $(NEW 046) 
  • trunk/phobos/std/traits.d

    r2008 r2019  
    937937// hasRawAliasing 
    938938 
    939939private template hasRawPointerImpl(T...) 
    940940{ 
    941941    static if (T.length == 0) 
    942942    { 
    943943        enum result = false; 
    944944    } 
    945945    else 
    946946    { 
    947         static if (is(T[0] foo : U*, U)
     947        static if (is(T[0] foo : U*, U) && !isFunctionPointer!(T[0])
    948948            enum hasRawAliasing = !is(U == immutable); 
    949949        else static if (is(T[0] foo : U[], U) && !isStaticArray!(T[0])) 
    950950            enum hasRawAliasing = !is(U == immutable); 
    951951        else static if (isAssociativeArray!(T[0])) 
    952952            enum hasRawAliasing = !is(T[0] == immutable); 
    953953        else 
    954954            enum hasRawAliasing = false; 
    955955        enum result = hasRawAliasing || hasRawPointerImpl!(T[1 .. $]).result; 
    956956    } 
    957957} 
    958958 
    959959private template HasRawLocalPointerImpl(T...) 
    960960{ 
    961961    static if (T.length == 0) 
    962962    { 
    963963        enum result = false; 
    964964    } 
    965965    else 
    966966    { 
    967         static if (is(T[0] foo : U*, U)
     967        static if (is(T[0] foo : U*, U) && !isFunctionPointer!(T[0])
    968968            enum hasRawLocalAliasing = !is(U == immutable) && !is(U == shared); 
    969969        else static if (is(T[0] foo : U[], U) && !isStaticArray!(T[0])) 
    970970            enum hasRawLocalAliasing = !is(U == immutable) && !is(U == shared); 
    971971        else static if (isAssociativeArray!(T[0])) 
    972972            enum hasRawLocalAliasing = !is(T[0] == immutable) && !is(T[0] == shared); 
    973973        else 
    974974            enum hasRawLocalAliasing = false; 
    975975        enum result = hasRawLocalAliasing || HasRawLocalPointerImpl!(T[1 .. $]).result; 
    976976    } 
    977977} 
     
    11501150    { 
    11511151        enum hasObjects = hasObjects!(U, T[1 .. $]); 
    11521152    } 
    11531153    else static if (is(T[0] == struct)) 
    11541154    { 
    11551155        enum hasObjects = hasObjects!( 
    11561156            RepresentationTypeTuple!(T[0]), T[1 .. $]); 
    11571157    } 
    11581158    else 
    11591159    { 
    1160         enum hasObjects = (is(T[0] == class) && !is(T[0] == immutable)) || 
    1161             hasObjects!(T[1 .. $]); 
     1160        enum hasObjects = ((is(T[0] == class) || is(T[0] == interface)) 
     1161            && !is(T[0] == immutable)) || hasObjects!(T[1 .. $]); 
    11621162    } 
    11631163} 
    11641164 
    11651165/* 
    11661166Statically evaluates to $(D true) if and only if $(D T)'s 
    11671167representation includes at least one non-immutable non-shared object 
    11681168reference. 
    11691169*/ 
    11701170 
    11711171private template hasUnsharedObjects(T...) 
     
    11781178    { 
    11791179        enum hasUnsharedObjects = hasUnsharedObjects!(U, T[1 .. $]); 
    11801180    } 
    11811181    else static if (is(T[0] == struct)) 
    11821182    { 
    11831183        enum hasUnsharedObjects = hasUnsharedObjects!( 
    11841184            RepresentationTypeTuple!(T[0]), T[1 .. $]); 
    11851185    } 
    11861186    else 
    11871187    { 
    1188         enum hasUnsharedObjects = (is(T[0] == class) && 
     1188        enum hasUnsharedObjects = ((is(T[0] == class) || is(T[0] == interface)) && 
    11891189                                !is(T[0] == immutable) && !is(T[0] == shared)) || 
    11901190            hasUnsharedObjects!(T[1 .. $]); 
    11911191    } 
    11921192} 
    11931193 
    11941194/** 
    11951195Returns $(D true) if and only if $(D T)'s representation includes at 
    11961196least one of the following: $(OL $(LI a raw pointer $(D U*) and $(D U) 
    11971197is not immutable;) $(LI an array $(D U[]) and $(D U) is not 
    1198 immutable;) $(LI a reference to a class type $(D C) and $(D C) is not 
    1199 immutable.) $(LI an associative array that is not immutable.) 
     1198immutable;) $(LI a reference to a class or interface type $(D C) and $(D C) is 
     1199not immutable.) $(LI an associative array that is not immutable.) 
    12001200$(LI a delegate.)) 
    12011201*/ 
    12021202 
    12031203template hasAliasing(T...) 
    12041204{ 
    12051205    enum hasAliasing = hasRawAliasing!(T) || hasObjects!(T) || 
    12061206        anySatisfy!(isDelegate, T); 
    12071207} 
    12081208 
    12091209unittest 
     
    12121212    static assert(hasAliasing!(S1)); 
    12131213    struct S2 { string a; } 
    12141214    static assert(!hasAliasing!(S2)); 
    12151215    struct S3 { int a; immutable Object b; } 
    12161216    static assert(!hasAliasing!(S3)); 
    12171217    struct X { float[3] vals; } 
    12181218    static assert(!hasAliasing!X); 
    12191219    static assert(hasAliasing!(uint[uint])); 
    12201220    static assert(!hasAliasing!(immutable(uint[uint]))); 
    12211221    static assert(hasAliasing!(void delegate())); 
     1222    static assert(!hasAliasing!(void function())); 
     1223 
     1224    interface I; 
     1225    static assert(hasAliasing!I); 
    12221226} 
    12231227 
    12241228/** 
    12251229Returns $(D true) if and only if $(D T)'s representation includes at 
    12261230least one of the following: $(OL $(LI a raw pointer $(D U*);) $(LI an 
    12271231array $(D U[]);) $(LI a reference to a class type $(D C).) 
    12281232$(LI an associative array.) $(LI a delegate.)) 
    12291233 */ 
    12301234 
    12311235template hasIndirections(T) 
    12321236{ 
    12331237    enum hasIndirections = hasIndirectionsImpl!(RepresentationTypeTuple!T); 
    12341238} 
    12351239 
    12361240template hasIndirectionsImpl(T...) 
    12371241{ 
    12381242    static if (!T.length) 
    12391243    { 
    12401244        enum hasIndirectionsImpl = false; 
    12411245    } 
     1246    else static if(isFunctionPointer!(T[0])) 
     1247    { 
     1248        enum hasIndirectionsImpl = hasIndirectionsImpl!(T[1 .. $]); 
     1249    } 
    12421250    else 
    12431251    { 
    12441252        enum hasIndirectionsImpl = isPointer!(T[0]) || isDynamicArray!(T[0]) || 
    12451253            is (T[0] : const(Object)) || isAssociativeArray!(T[0]) || 
    1246             isDelegate!(T[0]) || hasIndirectionsImpl!(T[1 .. $]); 
     1254            isDelegate!(T[0]) || is(T[0] == interface) 
     1255            || hasIndirectionsImpl!(T[1 .. $]); 
    12471256    } 
    12481257} 
    12491258 
    12501259unittest 
    12511260{ 
    12521261    struct S1 { int a; Object b; } 
    12531262    static assert(hasIndirections!(S1)); 
    12541263    struct S2 { string a; } 
    12551264    static assert(hasIndirections!(S2)); 
    12561265    struct S3 { int a; immutable Object b; } 
    12571266    static assert(hasIndirections!(S3)); 
    12581267    static assert(hasIndirections!(int[string])); 
    12591268    static assert(hasIndirections!(void delegate())); 
     1269 
     1270    interface I; 
     1271    static assert(hasIndirections!I); 
     1272    static assert(!hasIndirections!(void function())); 
    12601273} 
    12611274 
    12621275// These are for backwards compatibility, are intentionally lacking ddoc, 
    12631276// and should eventually be deprecated. 
    12641277alias hasUnsharedAliasing hasLocalAliasing; 
    12651278alias hasRawUnsharedAliasing hasRawLocalAliasing; 
    12661279alias hasUnsharedObjects hasLocalObjects; 
    12671280 
    12681281/** 
    12691282Returns $(D true) if and only if $(D T)'s representation includes at 
     
    12991312    struct S5 { char[] a; } 
    13001313    static assert(hasUnsharedAliasing!(S5)); 
    13011314    struct S6 { shared char[] b; } 
    13021315    static assert(!hasUnsharedAliasing!(S6)); 
    13031316    struct S7 { float[3] vals; } 
    13041317    static assert(!hasUnsharedAliasing!(S7)); 
    13051318 
    13061319    static assert(hasUnsharedAliasing!(uint[uint])); 
    13071320    static assert(hasUnsharedAliasing!(void delegate())); 
    13081321    static assert(!hasUnsharedAliasing!(shared(void delegate()))); 
     1322    static assert(!hasUnsharedAliasing!(void function())); 
     1323 
     1324    interface I {} 
     1325    static assert(hasUnsharedAliasing!I); 
    13091326} 
    13101327 
    13111328/** 
    13121329 True if $(D S) or any type embedded directly in the representation of $(D S) 
    13131330 defines an elaborate copy constructor. Elaborate copy constructors are 
    13141331 introduced by defining $(D this(this)) for a $(D struct). (Non-struct types 
    13151332 never have elaborate copy constructors.) 
    13161333 */ 
    13171334template hasElaborateCopyConstructor(S) 
    13181335{