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

Changeset 1705

Show
Ignore:
Timestamp:
07/01/10 03:26:52 (14 years ago)
Author:
dsimcha
Message:

Bug 2627: std.traits.hasAliasing reports true for static arrays. Also unlisted bug in std.traits.isAssociativeArray.

Files:

Legend:

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

    r1702 r1705  
    66$(VERSION 048, Jun 11, 2010, =================================================, 
    77 
    88    $(WHATSNEW 
    99    $(LI std.string: icmp() now works with all built-in string types.) 
    1010    ) 
    1111    $(BUGSFIXED 
    1212    $(L1 $(Unlisted Bug): std.algorithm.filter not a forward range) 
    1313    $(L1 $(Unlisted Bug): std.algorithm.Uniq requires a bidirectional range)  
    1414    $(L1 $(Unlisted Bug): std.algorithm.Uniq missing a save() function)  
    1515    $(L1 $(Unlisted Bug): std.algorithm.Group missing a save() function)  
     16    $(L1 $(Unlisted Bug): std.traits.isAssociativeArray reports true for structs w/ keys, values properties)  
    1617    $(LI $(BUGZILLA 978): std.utf's toUTF* functions accept some invalid and reject some valid UTF) 
    1718    $(LI $(BUGZILLA 996): Error in doc on implicit conversion between pointer and array) 
    1819    $(LI $(BUGZILLA 2275): std.utf.toUTF16z() should return const(wchar)*) 
     20    $(LI $(BUGZILLA 2627): std.traits.hasAliasing reports true for static arrays) 
    1921    $(LI $(BUGZILLA 2872): Length, opIndex for Map) 
    2022    $(LI $(BUGZILLA 3202): std.math.pow cause dead loop) 
    2123    $(LI $(BUGZILLA 3355): std.string.cmp works incorrectly for mixed-type and different-length strings) 
    2224    $(LI $(BUGZILLA 3386): to!bool(string) is not implemented) 
    2325    $(LI $(BUGZILLA 3436): std.functional.compose with only one function) 
    2426    $(LI $(BUGZILLA 3439): std.range.Sequence.opIndex not consistent after calling popFront().) 
    2527    $(LI $(BUGZILLA 3447): std.file uses unconventional file permissions) 
    2628    $(LI $(BUGZILLA 3872): std.algorithm.filter could become bidirectional if its input range is bidir) 
    2729    $(LI $(BUGZILLA 3874): std.range.stride assumes a bidirectional input range) 
    2830    $(LI $(BUGZILLA 3937): os.path.dirname fails on absolute path) 
  • trunk/phobos/std/traits.d

    r1680 r1705  
    841841private template HasRawPointerImpl(T...) 
    842842{ 
    843843    static if (T.length == 0) 
    844844    { 
    845845        enum result = false; 
    846846    } 
    847847    else 
    848848    { 
    849849        static if (is(T[0] foo : U*, U)) 
    850850            enum hasRawAliasing = !is(U == immutable); 
    851         else static if (is(T[0] foo : U[], U)
     851        else static if (is(T[0] foo : U[], U) && !isStaticArray!(T[0])
    852852            enum hasRawAliasing = !is(U == immutable); 
    853853        else 
    854854            enum hasRawAliasing = false; 
    855855        enum result = hasRawAliasing || HasRawPointerImpl!(T[1 .. $]).result; 
    856856    } 
    857857} 
    858858 
    859859private template HasRawLocalPointerImpl(T...) 
    860860{ 
    861861    static if (T.length == 0) 
     
    10981098} 
    10991099 
    11001100unittest 
    11011101{ 
    11021102    struct S1 { int a; Object b; } 
    11031103    static assert(hasAliasing!(S1)); 
    11041104    struct S2 { string a; } 
    11051105    static assert(!hasAliasing!(S2)); 
    11061106    struct S3 { int a; immutable Object b; } 
    11071107    static assert(!hasAliasing!(S3)); 
     1108    struct X { float[3] vals; } 
     1109    static assert(!hasAliasing!X); 
    11081110} 
    11091111 
    11101112/** 
    11111113Returns $(D true) if and only if $(D T)'s representation includes at 
    11121114least one of the following: $(OL $(LI a raw pointer $(D U*) and $(D U) 
    11131115is not immutable or shared;) $(LI an array $(D U[]) and $(D U) is not 
    11141116immutable or shared;) $(LI a reference to a class type $(D C) and 
    11151117$(D C) is not immutable or shared.)) 
    11161118*/ 
    11171119 
     
    20682070    static assert(!isSomeChar!(dstring)); 
    20692071    static assert(!isSomeChar!(char[4])); 
    20702072} 
    20712073 
    20722074/** 
    20732075 * Detect whether T is an associative array type 
    20742076 */ 
    20752077 
    20762078template isAssociativeArray(T) 
    20772079{ 
    2078     enum bool isAssociativeArray = 
    2079         is(typeof(T.keys)) && is(typeof(T.values)); 
    2080 
    2081  
    2082 unittest 
    2083 
     2080    enum bool isAssociativeArray = __traits(isAssociativeArray, T); 
     2081
     2082 
     2083unittest 
     2084
     2085    struct Foo { 
     2086        @property uint[] keys() { 
     2087            return null; 
     2088        } 
     2089 
     2090        @property uint[] values() { 
     2091            return null; 
     2092        } 
     2093    } 
     2094 
     2095    static assert(!isAssociativeArray!(Foo)); 
    20842096    static assert(!isAssociativeArray!(int)); 
    20852097    static assert(!isAssociativeArray!(int[])); 
    20862098    static assert(isAssociativeArray!(int[int])); 
    20872099    static assert(isAssociativeArray!(int[string])); 
    20882100    static assert(isAssociativeArray!(immutable(char[5])[int])); 
    20892101} 
    20902102 
    20912103/** 
    20922104 * Detect whether type T is a static array. 
    20932105 */