Add test for a case fixed by commit 6a4a61d9e1 (cmForEachCommand: prevent leakage, 2017-10-09). Prior to that fix, this test case could trigger an assertion failure. Fixes: #17464
6a4a61d9e1