Bug #21629
openRuby-3.4.7 prints -Wdefault-const-init-field-unsafe warnings on clang / llvm 21
Description
Here is the error I encountered. This is using clang version 21.1.3 as the compiler toolchain on Darwin.
DYLD_LIBRARY_PATH=.:../../.. ASAN_OPTIONS=detect_leaks=0 "clang -I../../../.ext/include/x86_64-darwin16 -I../../../../ruby-3.4.7/include -I../../../../ruby-3.4.7/ext/-test-/public_header_warnings -I/usr/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -fstack-protector-strong -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fdeclspec -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wextra-tokens -Wdeprecated-declarations -Wdivision-by-zero -Wdiv-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wmisleading-indentation -Wundef -fno-common -pipe -D_TEST_OK -Werror -c conftest.c"
In file included from conftest.c:1:
In file included from ../../../../ruby-3.4.7/include/ruby.h:38:
In file included from ../../../../ruby-3.4.7/include/ruby/ruby.h:28:
In file included from ../../../../ruby-3.4.7/include/ruby/internal/arithmetic.h:24:
In file included from ../../../../ruby-3.4.7/include/ruby/internal/arithmetic/char.h:29:
../../../../ruby-3.4.7/include/ruby/internal/core/rstring.h:398:24: error: default initialization of an object of type 'struct RString' with const member leaves the object uninitialized [-Werror,-Wdefault-const-init-field-unsafe]
398 | struct RString retval;
| ^
../../../../ruby-3.4.7/include/ruby/internal/core/rbasic.h:86:17: note: member 'klass' declared 'const' here
86 | const VALUE klass;
| ^
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5: return !!argv[argc];
6: }
/* end */
The configuration is the following:
CC=clang CXX=clang++ CPPFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib ../ruby-3.4.7/configure --enable-shared --with-rdoc=ri,html
Files
Updated by debo (David Bohman) about 4 hours ago
Let me know if you would like me to attach the entire build log.
Updated by debo (David Bohman) about 4 hours ago
Note that this is a tarball build.
Updated by k0kubun (Takashi Kokubun) about 4 hours ago
· Edited
- Status changed from Open to Feedback
- ruby -v changed from ruby 3.4.6 (2025-09-16 revision dbd83256b1) +PRISM [x86_64-darwin16] to ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [arm64-darwin16]
Let me know if you would like me to attach the entire build log.
Please do. I'm not sure how an error in one of the things checked by configure (conftest.c) leads to a build failure from this log.
I confirmed that I can build the same tarball of Ruby 3.4.7 with Apple clang 17.0.0 on darwin25. You might want to consider testing it with Apple clang installed by XCode command-line tools and/or upgrading your macOS to a non-EOL version (Apple's support of darwin16/macOS 10.12 has ended in 2019).
Updated by k0kubun (Takashi Kokubun) about 4 hours ago
- ruby -v changed from ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [arm64-darwin16] to ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [x86_64-darwin16]
Updated by k0kubun (Takashi Kokubun) about 4 hours ago
- Subject changed from Ruby-3.4.7 fails to build using clang / llvm to Ruby-3.4.7 fails to build using clang / llvm 21
- Status changed from Feedback to Open
I'll see if I can reproduce it with clang 21 on my end too
Updated by debo (David Bohman) about 4 hours ago
- Subject changed from Ruby-3.4.7 fails to build using clang / llvm 21 to Ruby-3.4.7 fails to build using clang / llvm
Note that I was using llvm-21.1.1 as the compiler toolchain when I built ruby-3.4.6. I'll try building ruby-3.4.6 again.
Updated by debo (David Bohman) about 4 hours ago
- File ruby-log.txt ruby-log.txt added
Attaching the build log for ruby-3.4.7.
Updated by k0kubun (Takashi Kokubun) about 4 hours ago
· Edited
- File ruby-log-2.txt ruby-log-2.txt added
- Status changed from Open to Feedback
Attaching the build log for ruby-3.4.7.
Could you also include the logs of configure and the commands you ran (both configure and make)? As an example, I've attached mine.
As shown in the attached log, it succeeded with llvm-21. So this is not an issue of Ruby 3.4.7 with LLVM 21 on a still-supported macOS version. As such, I strongly encourage you to test it after upgrading your macOS to a non-EOL version.
Updated by k0kubun (Takashi Kokubun) about 3 hours ago
- Subject changed from Ruby-3.4.7 fails to build using clang / llvm to Ruby-3.4.7 prints -Wdefault-const-init-field-unsafe warnings on clang / llvm21
- Status changed from Feedback to Open
- Backport changed from 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN to 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: REQUIRED
To me, the direct cause of the build failure seems to be -Werror
added by your environment. I don't know what part of llvm-21 or darwin-16 on Intel Mac leads to adding -Werror
, but it's unfortunately normal that new compiler versions show warnings on Ruby builds, so you shouldn't let warnings fail your Ruby build.
I'll repurpose this ticket for fixing the -Wdefault-const-init-field-unsafe
warning. But the fact that you have -Werror
in your build environment seems like a separate problem.
Updated by k0kubun (Takashi Kokubun) about 3 hours ago
- Subject changed from Ruby-3.4.7 prints -Wdefault-const-init-field-unsafe warnings on clang / llvm21 to Ruby-3.4.7 prints -Wdefault-const-init-field-unsafe warnings on clang / llvm 21
Updated by debo (David Bohman) about 3 hours ago
- Subject changed from Ruby-3.4.7 prints -Wdefault-const-init-field-unsafe warnings on clang / llvm 21 to Ruby-3.4.7 fails to build using clang / llvm
I don't understand. The ruby build is what added the -Werror to the compile that failed.
Updated by nobu (Nobuyoshi Nakada) about 2 hours ago
- Backport changed from 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: REQUIRED to 3.2: REQUIRED, 3.3: REQUIRED, 3.4: REQUIRED
Updated by k0kubun (Takashi Kokubun) about 2 hours ago
· Edited
- Subject changed from Ruby-3.4.7 fails to build using clang / llvm to Ruby-3.4.7 prints -Wdefault-const-init-field-unsafe warnings on clang / llvm 21
The ruby build is what added the -Werror to the compile that failed.
Could you point out the code that does it? As I said before, it didn't in my environment (Ruby 3.4.7, macOS 26, llvm-21), so I can't find the thing that I can't reproduce. You still haven't provided the logs of configure that I asked for, so it's also making it harder to figure out.
Updated by rhenium (Kazuki Yamaguchi) about 2 hours ago
The attached ruby-log.txt
seems to show the build was successful, but the test case meant to catch this kind of problem failed, as intended:
*** Following extensions are not compiled:
-test-/public_header_warnings:
Could not be configured. It will not be installed.
/tera/tera/debo/Projects/ruby/ruby-3.4.7/ext/-test-/public_header_warnings/extconf.rb:14: baseline compiler warning test failed
Check ext/-test-/public_header_warnings/mkmf.log for more details.
*** Fix the problems, then remove these directories and try again if you want.
Updated by debo (David Bohman) about 2 hours ago
- File ruby-config-log.txt ruby-config-log.txt added
Here is the configure log.
Updated by debo (David Bohman) about 2 hours ago
· Edited
I just built ruby with make -j <n>
where <n>
is the number of cpu threads available on this machine.
Updated by debo (David Bohman) about 2 hours ago
The fact that the ruby build gets these warnings seems to be new in clang 21.
Updated by debo (David Bohman) about 2 hours ago
You are correct, it does build and install:
ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [x86_64-darwin16]