From b6aaef42fb23c366d2b8a27c9e2a2a09d9c075ec Mon Sep 17 00:00:00 2001 From: Matt Staveley-Taylor Date: Sun, 3 Nov 2024 01:56:43 +0100 Subject: [PATCH] ci: check public headers conform to c++ ISO standards --- .github/workflows/ci.yml | 22 +++++++++++++++------- options/ansi/include/uchar.h | 5 +++-- options/posix/include/fcntl.h | 2 +- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 725876f70a..755da520f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,23 +53,31 @@ jobs: - name: Build mlibc run: 'xbstrap install ${{matrix.builds}}' working-directory: build/ - - name: Check public headers conform to C89/C99/C11 + - name: Check public headers conform to ISO standards with pedantic warnings if: ${{matrix.builds == 'mlibc-headers-only'}} working-directory: build/ run: | + shopt -s globstar GCC_ARCH="${{matrix.arch}}" case "$GCC_ARCH" in "x86") GCC_ARCH="i686" ;; esac - ALL_HDRS="packages/${{matrix.builds}}/usr/include/**.h" - GCC_ARGS="$GCC_ARCH-linux-mlibc-gcc -x c -S /dev/null -o /dev/null -I packages/${{matrix.builds}}/usr/include -I packages/linux-headers/usr/include -nostdlib -Werror -Wpedantic -Wsystem-headers" + ALL_INCLUDES="-- -include\0%s\0 packages/${{matrix.builds}}/usr/include/**/*.h" + GCC_ARGS="-S /dev/null -o /dev/null -I packages/${{matrix.builds}}/usr/include -I packages/linux-headers/usr/include -nostdlib -Werror -Wpedantic -Wsystem-headers" + GCC_C_ARGS="$GCC_ARCH-linux-mlibc-gcc -x c $GCC_ARGS" + GCC_CXX_ARGS="$GCC_ARCH-linux-mlibc-g++ -x c++ $GCC_ARGS" - # For C89, exclude complex.h, and -Wlong-long - printf -- '-include\0%s\0' $ALL_HDRS | sed 's/complex.h/stdio.h/' | xargs -0 $GCC_ARGS -std=c89 -Wno-long-long - printf -- '-include\0%s\0' $ALL_HDRS | xargs -0 $GCC_ARGS -std=c99 - printf -- '-include\0%s\0' $ALL_HDRS | xargs -0 $GCC_ARGS -std=c11 + # For C89, exclude complex.h. We also exclude -Wlong-long because fixing it mostly involves adding + # __extension__ to a bunch of places (and musl doesn't even bother). + printf $ALL_INCLUDES | sed 's/complex.h/stdio.h/' | xargs -0 $GCC_C_ARGS -std=c89 -Wno-long-long + printf $ALL_INCLUDES | xargs -0 $GCC_C_ARGS -std=c99 + printf $ALL_INCLUDES | xargs -0 $GCC_C_ARGS -std=c11 + printf $ALL_INCLUDES | xargs -0 $GCC_CXX_ARGS -std=c++98 -Wno-long-long + printf $ALL_INCLUDES | xargs -0 $GCC_CXX_ARGS -std=c++11 + printf $ALL_INCLUDES | xargs -0 $GCC_CXX_ARGS -std=c++14 + printf $ALL_INCLUDES | xargs -0 $GCC_CXX_ARGS -std=c++17 - name: Test mlibc run: 'meson test -v -C pkg-builds/${{matrix.builds}}' working-directory: build/ diff --git a/options/ansi/include/uchar.h b/options/ansi/include/uchar.h index b430c6c6e6..16ba7d016b 100644 --- a/options/ansi/include/uchar.h +++ b/options/ansi/include/uchar.h @@ -8,10 +8,11 @@ extern "C" { #include #include -#ifndef __cplusplus +/* These are builtin types since C++11. */ +#if !defined(__cplusplus) || __cplusplus < 201100L typedef __CHAR16_TYPE__ char16_t; typedef __CHAR32_TYPE__ char32_t; -#endif /* __cplusplus */ +#endif #ifndef __MLIBC_ABI_ONLY diff --git a/options/posix/include/fcntl.h b/options/posix/include/fcntl.h index 079a6820c7..65c6678fac 100644 --- a/options/posix/include/fcntl.h +++ b/options/posix/include/fcntl.h @@ -53,7 +53,7 @@ int posix_fallocate(int __fd, off_t __offset, off_t __size); struct file_handle { unsigned int handle_bytes; int handle_type; - unsigned char f_handle[0]; + __extension__ unsigned char f_handle[0]; }; #endif