mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 22:50:38 +03:00
Make side effect on strongly pure function call
This commit is contained in:
parent
a38148f38e
commit
5b39ab253c
4 changed files with 22 additions and 27 deletions
|
@ -2985,9 +2985,9 @@ unittest
|
||||||
//static assert(!is(typeof(Appender!string(cc))));
|
//static assert(!is(typeof(Appender!string(cc))));
|
||||||
|
|
||||||
//This should always work:
|
//This should always work:
|
||||||
appender!string(null);
|
{auto app = appender!string(null);}
|
||||||
appender!(const(char)[])(null);
|
{auto app = appender!(const(char)[])(null);}
|
||||||
appender!(char[])(null);
|
{auto app = appender!(char[])(null);}
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest //Test large allocations (for GC.extend)
|
unittest //Test large allocations (for GC.extend)
|
||||||
|
|
|
@ -2052,7 +2052,7 @@ unittest
|
||||||
test([ 1, 2, 3, 4, 5, 6 ], [ 6, 5, 4, 3, 2, 1 ]);
|
test([ 1, 2, 3, 4, 5, 6 ], [ 6, 5, 4, 3, 2, 1 ]);
|
||||||
|
|
||||||
immutable foo = [1,2,3].idup;
|
immutable foo = [1,2,3].idup;
|
||||||
retro(foo);
|
auto r = retro(foo);
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
|
@ -9210,12 +9210,7 @@ assert(buffer2 == [11, 12, 13, 14, 15]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
private static void _testSave(R)(R* range)
|
static if(isSafe!((R* r) => (*r).save))
|
||||||
{
|
|
||||||
(*range).save;
|
|
||||||
}
|
|
||||||
|
|
||||||
static if(isSafe!(_testSave!R))
|
|
||||||
{
|
{
|
||||||
@property auto save() @trusted
|
@property auto save() @trusted
|
||||||
{
|
{
|
||||||
|
|
32
std/utf.d
32
std/utf.d
|
@ -507,10 +507,10 @@ uint stride(S)(auto ref S str)
|
||||||
foreach (S; TypeTuple!(wchar[], const wchar[], wstring))
|
foreach (S; TypeTuple!(wchar[], const wchar[], wstring))
|
||||||
{
|
{
|
||||||
enum str = to!S("hello world");
|
enum str = to!S("hello world");
|
||||||
static assert(isSafe!({ stride(str, 0); }));
|
static assert(isSafe!(() => stride(str, 0)));
|
||||||
static assert(isSafe!({ stride(str); }));
|
static assert(isSafe!(() => stride(str) ));
|
||||||
static assert((functionAttributes!({ stride(str, 0); }) & FunctionAttribute.pure_) != 0);
|
static assert((functionAttributes!(() => stride(str, 0)) & FunctionAttribute.pure_) != 0);
|
||||||
static assert((functionAttributes!({ stride(str); }) & FunctionAttribute.pure_) != 0);
|
static assert((functionAttributes!(() => stride(str) ) & FunctionAttribute.pure_) != 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -623,10 +623,10 @@ unittest
|
||||||
foreach (S; TypeTuple!(wchar[], const wchar[], wstring))
|
foreach (S; TypeTuple!(wchar[], const wchar[], wstring))
|
||||||
{
|
{
|
||||||
enum str = to!S("hello world");
|
enum str = to!S("hello world");
|
||||||
static assert(isSafe!({ strideBack(str, 0); }));
|
static assert(isSafe!(() => strideBack(str, 0)));
|
||||||
static assert(isSafe!({ strideBack(str); }));
|
static assert(isSafe!(() => strideBack(str) ));
|
||||||
static assert((functionAttributes!({ strideBack(str, 0); }) & FunctionAttribute.pure_) != 0);
|
static assert((functionAttributes!(() => strideBack(str, 0)) & FunctionAttribute.pure_) != 0);
|
||||||
static assert((functionAttributes!({ strideBack(str); }) & FunctionAttribute.pure_) != 0);
|
static assert((functionAttributes!(() => strideBack(str) ) & FunctionAttribute.pure_) != 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -710,10 +710,10 @@ unittest
|
||||||
foreach (S; TypeTuple!(dchar[], const dchar[], dstring))
|
foreach (S; TypeTuple!(dchar[], const dchar[], dstring))
|
||||||
{
|
{
|
||||||
enum str = to!S("hello world");
|
enum str = to!S("hello world");
|
||||||
static assert(isSafe!({ stride(str, 0); }));
|
static assert(isSafe!(() => stride(str, 0)));
|
||||||
static assert(isSafe!({ stride(str); }));
|
static assert(isSafe!(() => stride(str) ));
|
||||||
static assert((functionAttributes!({ stride(str, 0); }) & FunctionAttribute.pure_) != 0);
|
static assert((functionAttributes!(() => stride(str, 0)) & FunctionAttribute.pure_) != 0);
|
||||||
static assert((functionAttributes!({ stride(str); }) & FunctionAttribute.pure_) != 0);
|
static assert((functionAttributes!(() => stride(str) ) & FunctionAttribute.pure_) != 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -807,10 +807,10 @@ unittest
|
||||||
foreach (S; TypeTuple!(dchar[], const dchar[], dstring))
|
foreach (S; TypeTuple!(dchar[], const dchar[], dstring))
|
||||||
{
|
{
|
||||||
enum str = to!S("hello world");
|
enum str = to!S("hello world");
|
||||||
static assert(isSafe!({ strideBack(str, 0); }));
|
static assert(isSafe!(() => strideBack(str, 0)));
|
||||||
static assert(isSafe!({ strideBack(str); }));
|
static assert(isSafe!(() => strideBack(str) ));
|
||||||
static assert((functionAttributes!({ strideBack(str, 0); }) & FunctionAttribute.pure_) != 0);
|
static assert((functionAttributes!(() => strideBack(str, 0)) & FunctionAttribute.pure_) != 0);
|
||||||
static assert((functionAttributes!({ strideBack(str); }) & FunctionAttribute.pure_) != 0);
|
static assert((functionAttributes!(() => strideBack(str) ) & FunctionAttribute.pure_) != 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ int main(char[][] args)
|
||||||
{
|
{
|
||||||
// Bring in unit test for module by referencing function in it
|
// Bring in unit test for module by referencing function in it
|
||||||
|
|
||||||
cmp("foo", "bar"); // string
|
cast(void)cmp("foo", "bar"); // string
|
||||||
cast(void)filenameCharCmp('a', 'b'); // path
|
cast(void)filenameCharCmp('a', 'b'); // path
|
||||||
cast(void)isNaN(1.0); // math
|
cast(void)isNaN(1.0); // math
|
||||||
std.conv.to!double("1.0"); // std.conv
|
std.conv.to!double("1.0"); // std.conv
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue