RESOLVED FIXED 245176
[CMake] Clang warnings about C code being built in C++ mode
https://bugs.webkit.org/show_bug.cgi?id=245176
Summary [CMake] Clang warnings about C code being built in C++ mode
Adrian Perez
Reported 2022-09-14 05:06:30 PDT
I haven't researched the root cause yet, but it looks like either the build is using “clang++” to compile plain C files, or passing “-x c++” to the “clang” driver (less likely): [3/30/6151|2.0/s| 0%] Building CXX object Source/bmalloc/CMakeFiles/bmalloc.dir/libpas/src/libpas/bmalloc_heap.c.o clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] [3/31/6151|2.0/s| 0%] Building CXX object Source/bmalloc/CMakeFiles/bmalloc.dir/libpas/src/libpas/bmalloc_heap_config.c.o clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] [3/39/6151|2.5/s| 0%] Building CXX object Source/bmalloc/CMakeFiles/bmalloc.dir/libpas/src/libpas/jit_heap.c.o clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] [3/40/6151|2.5/s| 0%] Building CXX object Source/bmalloc/CMakeFiles/bmalloc.dir/libpas/src/libpas/jit_heap_config.c.o clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] [3/57/6151|3.4/s| 0%] Building CXX object Source/bmalloc/CMakeFiles/bmalloc.dir/libpas/src/libpas/pas_bitfit_page_config_kind.c.o clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] [3/95/6151|5.3/s| 1%] Building CXX object Source/bmalloc/CMakeFiles/bmalloc.dir/libpas/src/libpas/pas_fast_megapage_cache.c.o clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] [3/101/6151|5.5/s| 1%] Building CXX object Source/bmalloc/CMakeFiles/bmalloc.dir/libpas/src/libpas/pas_heap_config_kind.c.o clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] [3/152/6151|7.7/s| 2%] Building CXX object Source/bmalloc/CMakeFiles/bmalloc.dir/libpas/src/libpas/pas_segregated_page_config_kind.c.o clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] [3/167/6151|8.3/s| 2%] Building CXX object Source/bmalloc/CMakeFiles/bmalloc.dir/libpas/src/libpas/pas_thread_local_cache.c.o clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] [3/172/6151|8.5/s| 2%] Building CXX object Source/bmalloc/CMakeFiles/bmalloc.dir/libpas/src/libpas/pas_utility_heap_config.c.o clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated] ...unless this is intentional and some of the libpas files are expected to be built with a C++ compiler for some reason even if their suffix is “.c” (not very likely, I suppose).
Attachments
Adrian Perez
Comment 1 2022-09-14 05:07:35 PDT
This is easily reproducible with: CC=clang CXX=clang++ cmake -S. -Bbuild -DPORT=GTK -GNinja ninja -Cbuild
Fujii Hironori
Comment 2 2022-09-14 13:16:41 PDT
What about adding enable_language(C)?
Yusuke Suzuki
Comment 3 2022-09-14 13:35:42 PDT
This is intentional since these files cannot be compiled as C in GCC probably because GCC lacks some constant propagation feature, which requires this explicit C++ handling.
Yusuke Suzuki
Comment 4 2022-09-14 13:36:14 PDT
So, I think, if we are using clang, then we do not need to mark them as C++.
Stephan Szabo
Comment 5 2022-09-14 14:12:54 PDT
We'd noticed something similar in the past, but we thought it was something specific to our downstream compilers, so in our case we ended up forcing a -xc++ into the build in our toolchain. It feels like this should work from the CMake side (setting the language to CXX for a file that has .c extension), so if it's more general and happens in a test project, I wonder if it's something that should get handled inside the CMake code (well the modules for the compiler).
Stephan Szabo
Comment 6 2022-09-15 09:42:31 PDT
From discussion on CMake discourse, with a minimum 3.20 or policy CMP0119 set to NEW, we'd get the -xc++ automatically when setting the language, but that won't help us for older versions.
Lauro Moura
Comment 7 2022-10-26 06:49:36 PDT
EWS
Comment 8 2022-11-13 20:25:31 PST
Committed 256626@main (e071c895f5fc): <https://commits.webkit.org/256626@main> Reviewed commits have been landed. Closing PR #5814 and removing active labels.
Radar WebKit Bug Importer
Comment 9 2022-11-13 20:26:20 PST
Note You need to log in before you can comment on or make changes to this bug.