From: "jeremyevans0 (Jeremy Evans)" Date: 2021-12-05T03:51:39+00:00 Subject: [ruby-core:106492] [Ruby master Bug#18387] Backport of fix for #16798 to Ruby 2.6 introduced C99 syntax Issue #18387 has been reported by jeremyevans0 (Jeremy Evans). ---------------------------------------- Bug #18387: Backport of fix for #16798 to Ruby 2.6 introduced C99 syntax https://bugs.ruby-lang.org/issues/18387 * Author: jeremyevans0 (Jeremy Evans) * Status: Closed * Priority: Normal * Assignee: usa (Usaku NAKAMURA) * Backport: 2.6: REQUIRED, 2.7: DONTNEED, 3.0: DONTNEED ---------------------------------------- Building Ruby 2.6.9 on OpenBSD/sparc64 fails with the following error: ``` cc -O2 -pipe -fPIC -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fno-strict-overflow -fvisibility=hidden -DRUBY_EXPORT -DCANONICALIZATION_FOR_MATHN -DOPENSSL_NO_STATIC_ENGINE -I/usr/local/include -I. -I.ext/include/sparc64-openbsd -I./include -I. -I./enc/unicode/12.1.0 -o hash.o -c hash.c hash.c: In function 'keylist_delete': hash.c:5661: error: 'for' loop initial declaration used outside C99 mode ``` The system compiler in this case is gcc 4.2.1, which defaults to C89/C90. I believe Ruby didn't switch to C99 until Ruby 2.7, so I think this is a bug that should be fixed in the next release of Ruby 2.6. This issue was introduced by commit:fe85a3d5271c4e3aeda42ec32e9c3f9ee02b6897, a backport of commit:08529a61153e5c40f57a65272211357511d6e6db. This patch should hopefully fix it (untested): ```diff diff --git a/hash.c b/hash.c index 38440f4b96..65a0419af3 100644 --- a/hash.c +++ b/hash.c @@ -5655,10 +5655,10 @@ env_invert(void) static void keylist_delete(VALUE keys, VALUE key) { - long keylen, elen; + long keylen, elen, i; const char *keyptr, *eptr; RSTRING_GETMEM(key, keyptr, keylen); - for (long i=0; i