Permalink
Browse files

fix Issue 9309 - Regression (2.061): -O -release generates wrong code

In current, all nested functions should be weak purity at most.
  • Loading branch information...
1 parent c692f81 commit a3373759c41931171a5fd023ab7df8e9f1689879 @9rnsr 9rnsr committed Jan 13, 2013
Showing with 39 additions and 0 deletions.
  1. +2 −0 src/func.c
  2. +37 −0 test/runnable/test9309.d
View
@@ -2985,6 +2985,8 @@ enum PURE FuncDeclaration::isPure()
if (tf->purity == PUREfwdref)
tf->purityLevel();
enum PURE purity = tf->purity;
+ if (purity > PUREweak && isNested())
+ purity = PUREweak;
if (purity > PUREweak && needThis())
{ // The attribute of the 'this' reference affects purity strength
if (type->mod & (MODimmutable | MODwild))
View
@@ -0,0 +1,37 @@
+immutable(T)[] assumeUnique(T)(ref T[] array) pure nothrow
+{
+ auto result = cast(immutable(T)[]) array;
+ array = null;
+ return result;
+}
+
+pure nothrow
+private string escapeShellArguments()
+{
+ char[] buf;
+
+ @safe nothrow
+ char[] allocator(size_t size)
+ {
+ return buf = new char[size];
+ }
+
+ escapeShellArgument!allocator("foo");
+ return assumeUnique(buf);
+}
+
+@safe nothrow
+auto escapeShellArgument(alias allocator)(in char[] arg)
+{
+ auto buf = allocator(4);
+ buf[0] = 'f';
+ buf[1] = 'o';
+ buf[2] = 'o';
+ buf[3] = '\0';
+}
+
+void main()
+{
+ string res = escapeShellArguments();
+ if (res != "foo\0") assert(0);
+}

0 comments on commit a337375

Please sign in to comment.