From 55a23c53fe1e47b6d12d32a0fd5a9f68700c67e0 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 30 Nov 2025 14:26:59 -0500 Subject: [PATCH] Check for C++-17 header compatibility in CI (fixes #1567) --- CMakeLists.txt | 1 + build-scripts/build-linux | 2 ++ build-scripts/check-headers | 41 +++++++++++++++++++++++++++++++++++++++++ include/qpdf/Pl_StdioFile.hh | 2 -- job.sums | 2 +- manual/release-notes.rst | 4 ++++ 6 files changed, 49 insertions(+), 3 deletions(-) create mode 100755 build-scripts/check-headers diff --git a/CMakeLists.txt b/CMakeLists.txt index 1dfb234..f97313e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -169,6 +169,7 @@ endif() if(CXX_NEXT) set(CMAKE_CXX_STANDARD 23) else() + # See also build-scripts/check-headers set(CMAKE_CXX_STANDARD 20) endif() set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/build-scripts/build-linux b/build-scripts/build-linux index 3c0de7f..a1216b9 100755 --- a/build-scripts/build-linux +++ b/build-scripts/build-linux @@ -18,6 +18,8 @@ for i in $(./qpdf/qpdf --show-crypto | tail -n +2); do env QPDF_CRYPTO_PROVIDER=$i ctest --verbose -R '^qpdf$' done cd .. +# Perform additional tests on header files. +./build-scripts/check-headers export TMPDIR=$PWD/dist-tmp rm -rf $TMPDIR ./make_dist --ci diff --git a/build-scripts/check-headers b/build-scripts/check-headers new file mode 100755 index 0000000..5557c65 --- /dev/null +++ b/build-scripts/check-headers @@ -0,0 +1,41 @@ +#!/bin/bash +set -eo pipefail +cd $(dirname $0)/.. + +trap "rm -f a.cc" EXIT +declare -a headers +cd include +for i in qpdf/*.hh; do + if [[ ! $i =~ .*auto_.* ]] && ! grep -q >/dev/null 2>&1 QPDFOBJECT_OLD_HH $i; then + headers+=($i) + fi +done +cd .. +# Make sure each header file can be included in isolation and that the +# result can be compiled with the intended version of the C++ +# standard, which may be older than one we build with internally. +declare -a errors +for i in "${headers[@]}"; do + rm -f a.cc + cat > a.cc </dev/null 2>&1 -E "#\s*include\s*[<\"](concepts|coroutine|compare|ranges|format|source_location|version|span|bit|numbers|barrier|latch|semaphore|stop_token|syncstream)[>\"]" "include/$i"; then + errors+=("$i includes a non-C++-17 standard header") + fi +done +if [[ ${#errors[@]} -gt 0 ]]; then + echo "" + echo "Some header files had errors" + for i in "${errors[@]}"; do + echo "$i" + done + exit 2 +fi diff --git a/include/qpdf/Pl_StdioFile.hh b/include/qpdf/Pl_StdioFile.hh index 47e6fc9..9e0ad54 100644 --- a/include/qpdf/Pl_StdioFile.hh +++ b/include/qpdf/Pl_StdioFile.hh @@ -45,8 +45,6 @@ class QPDF_DLL_CLASS Pl_StdioFile: public Pipeline private: class Members; - ; - std::unique_ptr m; }; diff --git a/job.sums b/job.sums index 3fc3b9b..5502dfb 100644 --- a/job.sums +++ b/job.sums @@ -1,5 +1,5 @@ # Generated by generate_auto_job -CMakeLists.txt 18214e276670dc8beb2ab83f789c6d94941bc92b199b353f3943024cfd41d3bc +CMakeLists.txt 5b8566f49d7b8b96cd6f7404670f65a03851826364e52697c3a7a2206f0f3069 generate_auto_job 8e3175a515aa8837d8a01bba0346b04b3d777d70330ba5b7d52f691316054a34 include/qpdf/auto_job_c_att.hh 4c2b171ea00531db54720bf49a43f8b34481586ae7fb6cbf225099ee42bc5bb4 include/qpdf/auto_job_c_copy_att.hh 50609012bff14fd82f0649185940d617d05d530cdc522185c7f3920a561ccb42 diff --git a/manual/release-notes.rst b/manual/release-notes.rst index b2d6da0..27c030e 100644 --- a/manual/release-notes.rst +++ b/manual/release-notes.rst @@ -52,6 +52,10 @@ more detail. than ``unsigned char``) container and facilitate the efficient moving of its content into a `std::string``. + - Build fixes + + - Attempt to detect if any > C++-17 changes snuck into any public + headers. - CLI Enhancements -- libgit2 0.21.4