From 1175e8af0babc82727dce7d592cc56e262b3d93b Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Mon, 29 Apr 2024 19:26:48 +0200 Subject: [PATCH 1/9] Make each .cpp/.h file self-sufficient in `#include`s Until now, some parts of the code used symbols from the standard library without including the corresponding standard library header using `#include` to ensure that the symbol is defined. That is, they silently assumed that the header has been already included by "someone else". These assumptions were sometimes met in our code due to transitive inclusions. For example, the missing `#include ` in `tests/unittest.cpp` would not turn into a compile error, because `tests/unittest.cpp` included `kaitai/exceptions.h`, which contains `#include `. However, it is discouraged to rely on transitive inclusions, see https://google.github.io/styleguide/cppguide.html#Include_What_You_Use: > Do not rely on transitive inclusions. This allows people to remove > no-longer-needed `#include` statements from their headers without > breaking clients. This also applies to related headers - `foo.cc` > should include `bar.h` if it uses a symbol from it even if `foo.h` > includes `bar.h`. Instances of this problem in our code aren't limited to "maintainability issues" - they can also reduce portability. For instance, @roelschroeven apparently ran into a `strtoll not found` error in our `kaitai/kaitaistream.cpp` source file that he had to patch like this (see https://github.com/roelschroeven/kaitai_struct_cpp_stl_runtime/commit/db668fad3f14b95251061c7c4793d60d2d1fadd5): ```diff diff --git a/kaitai/kaitaistream.cpp b/kaitai/kaitaistream.cpp index a3810ab..4d5ded2 100644 --- a/kaitai/kaitaistream.cpp +++ b/kaitai/kaitaistream.cpp @@ -6,6 +6,7 @@ #include #include #include +#include // ======================================================================== // Integer from raw data with correct endianness @@ -585,7 +586,7 @@ int64_t kaitai::kstream::string_to_int(const std::string& str, int base) { char *str_end; errno = 0; - int64_t res = strtoll(str.c_str(), &str_end, base); + int64_t res = std::strtoll(str.c_str(), &str_end, base); // Check for successful conversion and throw an exception if the entire string was not converted if (str_end != str.c_str() + str.size()) { ``` This makes sense according to https://en.cppreference.com/w/cpp/string/byte/strtol - we shouldn't assume that `std::strtoll` exists when we don't have `#include ` anywhere in our code. It worked fine without it in CI and on my local gcc 12.3.0 only because some standard library header that we include happened to use `` as part of its implementation. For curiosity, I used this command locally to dump a tree that shows why each header was `#include`d: ``` c++ -DKS_STR_ENCODING_ICONV -DKS_ZLIB -I. -std=c++11 -H -MM ./kaitai/kaitaistream.cpp 2> kaitaistream-deps.log ``` So for example, we can see that on the gcc 12.3, the `` header includes `` for some reason, so that's one of the reasons there's no compile error if we forget `#include ` in `kaitaistream.cpp`: ``` . /usr/include/c++/12/algorithm .. /usr/include/c++/12/bits/stl_algo.h ... /usr/include/c++/12/cstdlib ``` This is completely implementation-specific, of course. There's nothing in the C++ standard that requires `` to include ``, and in other implementations this may not be the case at all. See also https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#sf10-avoid-dependencies-on-implicitly-included-names --- kaitai/exceptions.h | 4 ++-- kaitai/kaitaistream.cpp | 32 ++++++++++++++++++-------------- kaitai/kaitaistream.h | 15 ++++++++------- tests/gtest-nano.h | 4 ++-- tests/unittest.cpp | 8 +++++++- 5 files changed, 37 insertions(+), 26 deletions(-) diff --git a/kaitai/exceptions.h b/kaitai/exceptions.h index 8033b98..4d1c85f 100644 --- a/kaitai/exceptions.h +++ b/kaitai/exceptions.h @@ -3,8 +3,8 @@ #include -#include -#include +#include // std::runtime_error +#include // std::string // We need to use "noexcept" in virtual destructor of our exceptions // subclasses. Different compilers have different ideas on how to diff --git a/kaitai/kaitaistream.cpp b/kaitai/kaitaistream.cpp index 044aaab..aa6d73d 100644 --- a/kaitai/kaitaistream.cpp +++ b/kaitai/kaitaistream.cpp @@ -47,10 +47,18 @@ #endif #endif +#include // int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t + +#include // std::reverse +#include // errno, ERANGE +#include // std::strtoll #include // std::memcpy -#include -#include -#include +#include // std::streamsize +#include // std::istream +#include // std::stringstream, std::ostringstream +#include // std::runtime_error, std::invalid_argument, std::out_of_range +#include // std::string, std::getline +#include // std::vector #ifdef KAITAI_STREAM_H_CPP11_SUPPORT #include // std::enable_if, std::is_trivially_copyable, std::is_trivially_constructible @@ -156,9 +164,9 @@ uint64_t kaitai::kstream::pos() { } uint64_t kaitai::kstream::size() { - std::iostream::pos_type cur_pos = m_io->tellg(); - m_io->seekg(0, std::ios::end); - std::iostream::pos_type len = m_io->tellg(); + std::istream::pos_type cur_pos = m_io->tellg(); + m_io->seekg(0, std::istream::end); + std::istream::pos_type len = m_io->tellg(); m_io->seekg(cur_pos); return len; } @@ -466,9 +474,9 @@ std::string kaitai::kstream::read_bytes(std::streamsize len) { } std::string kaitai::kstream::read_bytes_full() { - std::iostream::pos_type p1 = m_io->tellg(); - m_io->seekg(0, std::ios::end); - std::iostream::pos_type p2 = m_io->tellg(); + std::istream::pos_type p1 = m_io->tellg(); + m_io->seekg(0, std::istream::end); + std::istream::pos_type p2 = m_io->tellg(); size_t len = p2 - p1; // Note: this requires a std::string to be backed with a @@ -638,7 +646,6 @@ int kaitai::kstream::mod(int a, int b) { return r; } -#include void kaitai::kstream::unsigned_to_decimal(uint64_t number, char *buffer) { // Implementation from https://ideone.com/nrQfA8 by Alf P. Steinbach // (see https://www.zverovich.net/2013/09/07/integer-to-string-conversion-in-cplusplus.html#comment-1033931478) @@ -659,7 +666,7 @@ int64_t kaitai::kstream::string_to_int(const std::string& str, int base) { char *str_end; errno = 0; - int64_t res = strtoll(str.c_str(), &str_end, base); + int64_t res = std::strtoll(str.c_str(), &str_end, base); // Check for successful conversion and throw an exception if the entire string was not converted if (str_end != str.c_str() + str.size()) { @@ -712,10 +719,7 @@ uint8_t kaitai::kstream::byte_array_max(const std::string val) { #endif #ifdef KS_STR_ENCODING_ICONV - #include -#include -#include std::string kaitai::kstream::bytes_to_str(const std::string src, const char *src_enc) { iconv_t cd = iconv_open(KS_STR_DEFAULT_ENCODING, src_enc); diff --git a/kaitai/kaitaistream.h b/kaitai/kaitaistream.h index d58ae8e..34b3cf0 100644 --- a/kaitai/kaitaistream.h +++ b/kaitai/kaitaistream.h @@ -9,13 +9,14 @@ #define KAITAI_STREAM_H_CPP11_SUPPORT #endif -#include -#include -#include -#include -#include -#include -#include +#include // int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t + +#include // std::streamsize +#include // std::istream +#include // std::numeric_limits +#include // std::istringstream +#include // std::string +#include // std::enable_if, std::is_integral namespace kaitai { diff --git a/tests/gtest-nano.h b/tests/gtest-nano.h index 4b03fb5..00bae3c 100644 --- a/tests/gtest-nano.h +++ b/tests/gtest-nano.h @@ -1,9 +1,9 @@ // gtest-nano.h implements very minimalistic GTest-compatible API that can be used to run tests in older // (C++98-compatible) environments. +#include #include #include -#include namespace testing { struct TestInfo { @@ -72,7 +72,7 @@ namespace testing { // Floating point comparison macro #define EXPECT_FLOAT_EQ(a, b) \ do { \ - if (fabs(a - b) < 1e-6) { \ + if (std::fabs(a - b) < 1e-6) { \ } else { \ ::testing::g_testPass = false; \ } \ diff --git a/tests/unittest.cpp b/tests/unittest.cpp index ce34152..d8f4e13 100644 --- a/tests/unittest.cpp +++ b/tests/unittest.cpp @@ -6,7 +6,13 @@ #include "kaitai/kaitaistream.h" #include "kaitai/exceptions.h" -#include + +#include // int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t + +#include // std::numeric_limits +#include // std::istringstream +#include // std::out_of_range, std::invalid_argument +#include // std::string #define SETUP_STREAM(...) \ const uint8_t input_bytes[] = { __VA_ARGS__ }; \ From a414d149768447485f67c8561f02ba074b910dd1 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Tue, 30 Apr 2024 01:52:15 +0200 Subject: [PATCH 2/9] Add `#include `, use `std::size_t` (not just `size_t`) We use `std::size_t` (and not the global `size_t`) because it is the only variant that `` is guaranteed to provide, see : > You must not assume that `` adds any names to the global > namespace, and you must not assume that `` adds any names to > namespace `std`. So technically we could do it the other way around (`#include ` and use `size_t` everywhere), but the `` headers are deprecated in C++ in favour of ``. Plus I think it's somewhat beneficial to use the `std::` prefix, because it reminds us that it's a type from the standard library, so it needs an `#include`. --- kaitai/kaitaistream.cpp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/kaitai/kaitaistream.cpp b/kaitai/kaitaistream.cpp index aa6d73d..352f99e 100644 --- a/kaitai/kaitaistream.cpp +++ b/kaitai/kaitaistream.cpp @@ -51,6 +51,7 @@ #include // std::reverse #include // errno, ERANGE +#include // std::size_t #include // std::strtoll #include // std::memcpy #include // std::streamsize @@ -477,7 +478,7 @@ std::string kaitai::kstream::read_bytes_full() { std::istream::pos_type p1 = m_io->tellg(); m_io->seekg(0, std::istream::end); std::istream::pos_type p2 = m_io->tellg(); - size_t len = p2 - p1; + std::size_t len = p2 - p1; // Note: this requires a std::string to be backed with a // contiguous buffer. Officially, it's a only requirement since @@ -548,22 +549,22 @@ std::string kaitai::kstream::bytes_terminate(std::string src, char term, bool in // ======================================================================== std::string kaitai::kstream::process_xor_one(std::string data, uint8_t key) { - size_t len = data.length(); + std::size_t len = data.length(); std::string result(len, ' '); - for (size_t i = 0; i < len; i++) + for (std::size_t i = 0; i < len; i++) result[i] = data[i] ^ key; return result; } std::string kaitai::kstream::process_xor_many(std::string data, std::string key) { - size_t len = data.length(); - size_t kl = key.length(); + std::size_t len = data.length(); + std::size_t kl = key.length(); std::string result(len, ' '); - size_t ki = 0; - for (size_t i = 0; i < len; i++) { + std::size_t ki = 0; + for (std::size_t i = 0; i < len; i++) { result[i] = data[i] ^ key[ki]; ki++; if (ki >= kl) @@ -574,10 +575,10 @@ std::string kaitai::kstream::process_xor_many(std::string data, std::string key) } std::string kaitai::kstream::process_rotate_left(std::string data, int amount) { - size_t len = data.length(); + std::size_t len = data.length(); std::string result(len, ' '); - for (size_t i = 0; i < len; i++) { + for (std::size_t i = 0; i < len; i++) { uint8_t bits = data[i]; result[i] = (bits << amount) | (bits >> (8 - amount)); } @@ -732,13 +733,13 @@ std::string kaitai::kstream::bytes_to_str(const std::string src, const char *src } } - size_t src_len = src.length(); - size_t src_left = src_len; + std::size_t src_len = src.length(); + std::size_t src_left = src_len; // Start with a buffer length of double the source length. - size_t dst_len = src_len * 2; + std::size_t dst_len = src_len * 2; std::string dst(dst_len, ' '); - size_t dst_left = dst_len; + std::size_t dst_left = dst_len; // NB: this should be const char *, but for some reason iconv() requires non-const in its 2nd argument, // so we force it with a cast. @@ -746,13 +747,13 @@ std::string kaitai::kstream::bytes_to_str(const std::string src, const char *src char *dst_ptr = &dst[0]; while (true) { - size_t res = iconv(cd, &src_ptr, &src_left, &dst_ptr, &dst_left); + std::size_t res = iconv(cd, &src_ptr, &src_left, &dst_ptr, &dst_left); - if (res == (size_t)-1) { + if (res == (std::size_t)-1) { if (errno == E2BIG) { // dst buffer is not enough to accomodate whole string // enlarge the buffer and try again - size_t dst_used = dst_len - dst_left; + std::size_t dst_used = dst_len - dst_left; dst_left += dst_len; dst_len += dst_len; dst.resize(dst_len); From c094e469b093f8e884b7dd229c71edbab9e5f5c1 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Tue, 30 Apr 2024 12:24:42 +0200 Subject: [PATCH 3/9] Add `KAITAI_STREAM_H_CPP11_SUPPORT` macro, fix C++98 compatibility See https://github.com/kaitai-io/kaitai_struct_cpp_stl_runtime/pull/72#discussion_r1584395613 The standard library header `` is only available since C++11 (see https://en.cppreference.com/w/cpp/header/type_traits), so we must not try to include it in C++98 mode. --- kaitai/exceptions.h | 2 +- kaitai/kaitaistream.h | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/kaitai/exceptions.h b/kaitai/exceptions.h index 4d1c85f..589c15e 100644 --- a/kaitai/exceptions.h +++ b/kaitai/exceptions.h @@ -11,7 +11,7 @@ // achieve that: C++98 compilers prefer `throw()`, C++11 and later // use `noexcept`. We define KS_NOEXCEPT macro for that. -#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900) +#ifdef KAITAI_STREAM_H_CPP11_SUPPORT #define KS_NOEXCEPT noexcept #else #define KS_NOEXCEPT throw() diff --git a/kaitai/kaitaistream.h b/kaitai/kaitaistream.h index 34b3cf0..60dab0b 100644 --- a/kaitai/kaitaistream.h +++ b/kaitai/kaitaistream.h @@ -16,7 +16,10 @@ #include // std::numeric_limits #include // std::istringstream #include // std::string + +#ifdef KAITAI_STREAM_H_CPP11_SUPPORT #include // std::enable_if, std::is_integral +#endif namespace kaitai { @@ -234,8 +237,7 @@ class kstream { * since C++11) in older C++ implementations. */ template -// check for C++11 support - https://stackoverflow.com/a/40512515 -#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900) +#ifdef KAITAI_STREAM_H_CPP11_SUPPORT // https://stackoverflow.com/a/27913885 typename std::enable_if< std::is_integral::value && From 6d422b212f494a3aa39b9a9245fcb76cf90c0ddc Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Fri, 3 May 2024 11:53:16 +0200 Subject: [PATCH 4/9] GH Actions: install include-what-you-use, integrate it with CMake See https://github.com/include-what-you-use/include-what-you-use/blob/93d8793081e5aa457114ef99d1e887390b370e4a/README.md#using-with-cmake --- .github/workflows/build.yml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 38e86ce..57244ff 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,14 +18,28 @@ jobs: - '20' steps: - uses: actions/checkout@v4 - - name: restore + - name: install GoogleTest run: | sudo apt-get update sudo apt-get install -y libgtest-dev + - name: install include-what-you-use (iwyu) + # NB: https://packages.ubuntu.com/jammy/iwyu apparently doesn't declare the `libclang-common-XXX-dev` package it + # needs as a dependency (without it, `include-what-you-use` fails with "fatal error: 'stddef.h' file not found" + # or similar), although this problem has been reported in 7 out of 7 bug reports at + # https://bugs.launchpad.net/ubuntu/+source/iwyu, the oldest one is from 2014. + # + # We intentionally specify an exact version of `iwyu` here, so that when a new version becomes available and we + # want to update to it, we'll have to change this hardcoded version manually and update the + # `libclang-common-XXX-dev` version accordingly (see + # https://github.com/include-what-you-use/include-what-you-use/blob/master/README.md#clang-compatibility). + run: sudo apt-get install -y iwyu=8.17-1 libclang-common-13-dev - name: build env: CPP_STANDARD: ${{ matrix.cpp-standard }} - run: .build/build -DCMAKE_CXX_STANDARD="$CPP_STANDARD" -DCMAKE_CXX_STANDARD_REQUIRED=ON -DCMAKE_CXX_EXTENSIONS=OFF + run: | + .build/build \ + -DCMAKE_CXX_STANDARD="$CPP_STANDARD" -DCMAKE_CXX_STANDARD_REQUIRED=ON -DCMAKE_CXX_EXTENSIONS=OFF \ + -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE='include-what-you-use;-Xiwyu;--verbose=3' - name: unittest run: .build/run-unittest From 195c173857f82953168f883e3cac9a9170cb6fcf Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Fri, 3 May 2024 13:55:04 +0200 Subject: [PATCH 5/9] Apply some fixes suggested by IWYU, suppress others See https://github.com/kaitai-io/kaitai_struct_cpp_stl_runtime/pull/72#issuecomment-2087715653 --- kaitai/kaitaistream.cpp | 17 ++++++++++++----- kaitai/kaitaistream.h | 5 ++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/kaitai/kaitaistream.cpp b/kaitai/kaitaistream.cpp index 352f99e..60ae80b 100644 --- a/kaitai/kaitaistream.cpp +++ b/kaitai/kaitaistream.cpp @@ -50,13 +50,12 @@ #include // int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t #include // std::reverse -#include // errno, ERANGE -#include // std::size_t -#include // std::strtoll +#include // errno, EINVAL, E2BIG, EILSEQ, ERANGE +#include // std::size_t, std::strtoll #include // std::memcpy #include // std::streamsize -#include // std::istream -#include // std::stringstream, std::ostringstream +#include // std::istream // IWYU pragma: keep +#include // std::stringstream, std::ostringstream // IWYU pragma: keep #include // std::runtime_error, std::invalid_argument, std::out_of_range #include // std::string, std::getline #include // std::vector @@ -589,6 +588,14 @@ std::string kaitai::kstream::process_rotate_left(std::string data, int amount) { #ifdef KS_ZLIB #include +// This instructs include-what-you-use not to suggest `#include ` just because it contains +// the definition of `Bytef`. It seems `` is not a header for public use or at least it's +// not considered necessary to include it on top of ``, because official usage examples that +// use `Bytef` only include ``, see +// https://github.com/madler/zlib/blob/0f51fb4933fc9ce18199cb2554dacea8033e7fd3/test/example.c#L71 +// +// IWYU pragma: no_include + std::string kaitai::kstream::process_zlib(std::string data) { int ret; diff --git a/kaitai/kaitaistream.h b/kaitai/kaitaistream.h index 60dab0b..58b4dee 100644 --- a/kaitai/kaitaistream.h +++ b/kaitai/kaitaistream.h @@ -11,10 +11,9 @@ #include // int8_t, int16_t, int32_t, int64_t, uint8_t, uint16_t, uint32_t, uint64_t -#include // std::streamsize -#include // std::istream +#include // std::streamsize, forward declaration of std::istream // IWYU pragma: keep #include // std::numeric_limits -#include // std::istringstream +#include // std::istringstream // IWYU pragma: keep #include // std::string #ifdef KAITAI_STREAM_H_CPP11_SUPPORT From 748f5c5c901d8c817f560db2011de5eb7649aa26 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Fri, 3 May 2024 17:56:36 +0200 Subject: [PATCH 6/9] CI: build GoogleTest 1.14 from source (was 1.11 via `apt install`) See https://github.com/kaitai-io/kaitai_struct_cpp_stl_runtime/pull/72#issuecomment-2093287161 --- .build/install-gtest | 26 ++++++++++++++++++++++++++ .github/workflows/build.yml | 8 ++++---- 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100755 .build/install-gtest diff --git a/.build/install-gtest b/.build/install-gtest new file mode 100755 index 0000000..03902b1 --- /dev/null +++ b/.build/install-gtest @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -ef + +# Build GoogleTest from source and install it +# +# See https://github.com/google/googletest/blob/d83fee138a9ae6cb7c03688a2d08d4043a39815d/googletest/README.md#build-with-cmake + +gtest_version_tag=v1.14.0 + +temp_dir=$(mktemp -d) +function cleanup { + rm -rf -- "$temp_dir" +} +trap 'cleanup' EXIT + +# Download +git clone --depth 1 -b "$gtest_version_tag" -- https://github.com/google/googletest.git "$temp_dir" +cd -- "$temp_dir" +mkdir build +cd build +# Configure - build only GoogleTest, not GoogleMock +cmake .. -DBUILD_GMOCK=OFF +# Build +make +# Install +sudo make install diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 57244ff..6e76588 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,9 +19,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: install GoogleTest - run: | - sudo apt-get update - sudo apt-get install -y libgtest-dev + run: .build/install-gtest - name: install include-what-you-use (iwyu) # NB: https://packages.ubuntu.com/jammy/iwyu apparently doesn't declare the `libclang-common-XXX-dev` package it # needs as a dependency (without it, `include-what-you-use` fails with "fatal error: 'stddef.h' file not found" @@ -32,7 +30,9 @@ jobs: # want to update to it, we'll have to change this hardcoded version manually and update the # `libclang-common-XXX-dev` version accordingly (see # https://github.com/include-what-you-use/include-what-you-use/blob/master/README.md#clang-compatibility). - run: sudo apt-get install -y iwyu=8.17-1 libclang-common-13-dev + run: | + sudo apt-get update + sudo apt-get install -y iwyu=8.17-1 libclang-common-13-dev - name: build env: CPP_STANDARD: ${{ matrix.cpp-standard }} From c00507b8d653a4ec08caf997c0fa0bd05f6e65e1 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Fri, 3 May 2024 18:06:57 +0200 Subject: [PATCH 7/9] Use `#include "gtest/gtest.h"` (not `<>`) to suppress IWYU warnings --- tests/unittest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unittest.cpp b/tests/unittest.cpp index d8f4e13..ae1a56d 100644 --- a/tests/unittest.cpp +++ b/tests/unittest.cpp @@ -1,7 +1,7 @@ #ifdef GTEST_NANO #include "tests/gtest-nano.h" #else -#include +#include "gtest/gtest.h" #endif #include "kaitai/kaitaistream.h" From 0fd74d44759ce2c9bc1625f04472972d2974d848 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Sat, 22 Jun 2024 23:53:30 +0200 Subject: [PATCH 8/9] Suppress IWYU warning about `#include ` IWYU is actually right that `sys/param.h` is not used on Linux. However, we need it for the BSD detection, so let's tell IWYU that we want to keep this "unnecessary" inclusion. --- kaitai/kaitaistream.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kaitai/kaitaistream.cpp b/kaitai/kaitaistream.cpp index 60ae80b..940cc37 100644 --- a/kaitai/kaitaistream.cpp +++ b/kaitai/kaitaistream.cpp @@ -29,7 +29,7 @@ #define __LITTLE_ENDIAN LITTLE_ENDIAN #else // At this point it's either Linux or BSD. Both have "sys/param.h", so it's safe to include -#include +#include // `BSD` macro // IWYU pragma: keep #if defined(BSD) // Supposed to work on FreeBSD: https://man.freebsd.org/cgi/man.cgi?query=bswap16&manpath=FreeBSD+14.0-RELEASE // Supposed to work on NetBSD: https://man.netbsd.org/NetBSD-10.0/bswap16.3 From 0373ae6f5420c4616748d32b9e0f42c9ea163e63 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Sun, 30 Jun 2024 13:32:04 +0200 Subject: [PATCH 9/9] .github/workflows/build.yml: reword comment --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6e76588..3886ad7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,11 +24,11 @@ jobs: # NB: https://packages.ubuntu.com/jammy/iwyu apparently doesn't declare the `libclang-common-XXX-dev` package it # needs as a dependency (without it, `include-what-you-use` fails with "fatal error: 'stddef.h' file not found" # or similar), although this problem has been reported in 7 out of 7 bug reports at - # https://bugs.launchpad.net/ubuntu/+source/iwyu, the oldest one is from 2014. + # https://bugs.launchpad.net/ubuntu/+source/iwyu, the oldest being from 2014. # - # We intentionally specify an exact version of `iwyu` here, so that when a new version becomes available and we - # want to update to it, we'll have to change this hardcoded version manually and update the - # `libclang-common-XXX-dev` version accordingly (see + # Therefore, we deliberately require a fixed version of `iwyu` along with the compatible + # `libclang-common-XXX-dev` package. When a new version becomes available and we want to update to it, we'll + # have to change this hardcoded version manually and bump the `libclang-common-XXX-dev` version accordingly (see # https://github.com/include-what-you-use/include-what-you-use/blob/master/README.md#clang-compatibility). run: | sudo apt-get update