Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kbuild: uapi: also test UAPI headers against C++ compilers

C++ language requirements differ from those of C.

Also test the headers against C++ compilers to make sure no errors
creep in accidentally.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Link: https://patch.msgid.link/20260316-kbuild-uapi-c-v2-5-35d6d0ed863f@weissschuh.net
Signed-off-by: Nicolas Schier <nsc@kernel.org>

authored by

Thomas Weißschuh and committed by
Nicolas Schier
dcc99abe b187c1a1

+28
+28
usr/include/Makefile
··· 10 10 UAPI_ARCH := $(or $(HEADER_ARCH),$(SRCARCH)) 11 11 12 12 override c_flags = $(KBUILD_USERCFLAGS) $(UAPI_CFLAGS) -Wp,-MMD,$(depfile) 13 + cxx_flags = $(filter-out -Wmissing-prototypes -Wstrict-prototypes -std=%, $(KBUILD_USERCFLAGS)) -std=c++98 13 14 14 15 # The following are excluded for now because they fail to build. 15 16 # ··· 61 60 62 61 # asm-generic/*.h is used by asm/*.h, and should not be included directly 63 62 no-header-test += asm-generic/% 63 + 64 + # The following are not compatible with C++. 65 + # 66 + # Do not add a new header to the list without legitimate reason. 67 + # Please consider to fix the header first. 68 + # 69 + # Sorted alphabetically. 70 + no-header-test-cxx += linux/auto_dev-ioctl.h 71 + no-header-test-cxx += linux/map_to_14segment.h 72 + no-header-test-cxx += linux/map_to_7segment.h 73 + no-header-test-cxx += linux/netfilter/xt_sctp.h 74 + no-header-test-cxx += linux/target_core_user.h 75 + no-header-test-cxx += linux/vhost.h 76 + no-header-test-cxx += linux/vhost_types.h 77 + no-header-test-cxx += linux/virtio_net.h 78 + no-header-test-cxx += linux/virtio_ring.h 79 + no-header-test-cxx += scsi/fc/fc_els.h 80 + 81 + ifeq ($(UAPI_ARCH),x86) 82 + no-header-test-cxx += asm/elf.h 83 + endif 64 84 65 85 # The following are using libc header and types. 66 86 # ··· 160 138 161 139 always-y := $(patsubst $(obj)/%.h,%.hdrtest, $(shell find $(obj) -name '*.h' 2>/dev/null)) 162 140 141 + # $(cc-option) forces '-x c' which breaks '-x c++' detection. 142 + cc-can-compile-cxx := $(call try-run,$(CC) $(CLANG_FLAGS) -c -x c++ /dev/null -o "$$TMP", 1) 143 + 163 144 target-libc = $(filter $(uses-libc), $*.h) 164 145 target-can-compile = $(filter-out $(no-header-test), $*.h) 146 + target-can-compile-cxx = $(and $(cc-can-compile-cxx), $(target-can-compile), $(filter-out $(no-header-test-cxx), $*.h)) 165 147 166 148 hdrtest-flags = -fsyntax-only -Werror \ 167 149 -nostdinc -I $(obj) $(if $(target-libc), -I $(srctree)/usr/dummy-include) ··· 175 149 cmd_hdrtest = \ 176 150 $(CC) $(c_flags) $(hdrtest-flags) -x c /dev/null \ 177 151 $(if $(target-can-compile), -include $< -include $<); \ 152 + $(if $(target-can-compile-cxx), \ 153 + $(CC) $(cxx_flags) $(hdrtest-flags) -x c++ /dev/null -include $<;) \ 178 154 $(PERL) $(src)/headers_check.pl $(obj) $<; \ 179 155 touch $@ 180 156