Commit 52a4253c707c007f5cdb4bcb424dd8d300e17229

Authored by Jay Berkenbilt
Committed by GitHub
2 parents 1a5c51b6 55a23c53

Merge pull request #1611 from jberkenbilt/c++-17-check

Check for C++-17 header compatibility in CI (fixes #1567)
CMakeLists.txt
... ... @@ -169,6 +169,7 @@ endif()
169 169 if(CXX_NEXT)
170 170 set(CMAKE_CXX_STANDARD 23)
171 171 else()
  172 + # See also build-scripts/check-headers
172 173 set(CMAKE_CXX_STANDARD 20)
173 174 endif()
174 175 set(CMAKE_CXX_EXTENSIONS OFF)
... ...
build-scripts/build-linux
... ... @@ -18,6 +18,8 @@ for i in $(./qpdf/qpdf --show-crypto | tail -n +2); do
18 18 env QPDF_CRYPTO_PROVIDER=$i ctest --verbose -R '^qpdf$'
19 19 done
20 20 cd ..
  21 +# Perform additional tests on header files.
  22 +./build-scripts/check-headers
21 23 export TMPDIR=$PWD/dist-tmp
22 24 rm -rf $TMPDIR
23 25 ./make_dist --ci
... ...
build-scripts/check-headers 0 → 100755
  1 +#!/bin/bash
  2 +set -eo pipefail
  3 +cd $(dirname $0)/..
  4 +
  5 +trap "rm -f a.cc" EXIT
  6 +declare -a headers
  7 +cd include
  8 +for i in qpdf/*.hh; do
  9 + if [[ ! $i =~ .*auto_.* ]] && ! grep -q >/dev/null 2>&1 QPDFOBJECT_OLD_HH $i; then
  10 + headers+=($i)
  11 + fi
  12 +done
  13 +cd ..
  14 +# Make sure each header file can be included in isolation and that the
  15 +# result can be compiled with the intended version of the C++
  16 +# standard, which may be older than one we build with internally.
  17 +declare -a errors
  18 +for i in "${headers[@]}"; do
  19 + rm -f a.cc
  20 + cat > a.cc <<EOF
  21 +#include "$i"
  22 +int main() { return 0; }
  23 +EOF
  24 + echo "Checking $i"
  25 + if ! g++ -std=c++17 -pedantic-errors -c -Iinclude a.cc -o /dev/null; then
  26 + errors+=("$i doesn't compile")
  27 + fi
  28 + # Fail if any C++20 headers are included. Modern g++/clang treat
  29 + # these as empty if the compiler standard is too old.
  30 + if grep -q >/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
  31 + errors+=("$i includes a non-C++-17 standard header")
  32 + fi
  33 +done
  34 +if [[ ${#errors[@]} -gt 0 ]]; then
  35 + echo ""
  36 + echo "Some header files had errors"
  37 + for i in "${errors[@]}"; do
  38 + echo "$i"
  39 + done
  40 + exit 2
  41 +fi
... ...
include/qpdf/Pl_StdioFile.hh
... ... @@ -45,8 +45,6 @@ class QPDF_DLL_CLASS Pl_StdioFile: public Pipeline
45 45  
46 46 private:
47 47 class Members;
48   - ;
49   -
50 48 std::unique_ptr<Members> m;
51 49 };
52 50  
... ...
job.sums
1 1 # Generated by generate_auto_job
2   -CMakeLists.txt 18214e276670dc8beb2ab83f789c6d94941bc92b199b353f3943024cfd41d3bc
  2 +CMakeLists.txt 5b8566f49d7b8b96cd6f7404670f65a03851826364e52697c3a7a2206f0f3069
3 3 generate_auto_job 8e3175a515aa8837d8a01bba0346b04b3d777d70330ba5b7d52f691316054a34
4 4 include/qpdf/auto_job_c_att.hh 4c2b171ea00531db54720bf49a43f8b34481586ae7fb6cbf225099ee42bc5bb4
5 5 include/qpdf/auto_job_c_copy_att.hh 50609012bff14fd82f0649185940d617d05d530cdc522185c7f3920a561ccb42
... ...
manual/release-notes.rst
... ... @@ -52,6 +52,10 @@ more detail.
52 52 than ``unsigned char``) container and facilitate the efficient moving
53 53 of its content into a `std::string``.
54 54  
  55 + - Build fixes
  56 +
  57 + - Attempt to detect if any > C++-17 changes snuck into any public
  58 + headers.
55 59  
56 60 - CLI Enhancements
57 61  
... ...