Fix Issue 23271 - Mark lowered DeclExps in array appends as exptemp (#14328)

This commit is contained in:
Max Haughton 2022-07-26 07:38:10 +01:00 committed by GitHub
parent 5843effb01
commit 0f2c2e8b60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View file

@ -10330,6 +10330,8 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
// `__appendtmp*` will be destroyed together with the array `exp.e1`.
auto vd = eValue2.isDeclarationExp().declaration.isVarDeclaration();
vd.storage_class |= STC.nodtor;
// Be more explicit that this "declaration" is local to the expression
vd.storage_class |= STC.exptemp;
}
auto ale = new ArrayLengthExp(exp.loc, value1);

View file

@ -0,0 +1,17 @@
/*
Tests to defend against false positives from the goto skips over decl errors
*/
// https://issues.dlang.org/show_bug.cgi?id=23271
class A {
private static A[] active;
private void test() {
foreach(a; active) {
if(a is this)
goto label;
}
// used to say Error: `goto` skips declaration of variable `s.A.test.__appendtmp4` at s.d(...)
active ~= this;
label:
return;
}
}