Skip to content
Browse files

Merge pull request #1474 from 9rnsr/fix9309

Issue 9309 - Regression (2.061): -O -release generates wrong code
  • Loading branch information...
2 parents 3904f7e + a337375 commit 7686d93349861f83e7c8adc1e0fad0f36f932e64 @WalterBright WalterBright committed
Showing with 39 additions and 0 deletions.
  1. +2 −0 src/func.c
  2. +37 −0 test/runnable/test9309.d
View
2 src/func.c
@@ -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
37 test/runnable/test9309.d
@@ -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 7686d93

Please sign in to comment.
Something went wrong with that request. Please try again.