From cd145314bab8f269c1e605a22689370602ccfb1b Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Fri, 3 May 2024 13:55:04 +0200 Subject: [PATCH] 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 9760500..190e97c 100644 --- a/kaitai/kaitaistream.cpp +++ b/kaitai/kaitaistream.cpp @@ -35,12 +35,11 @@ #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::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 @@ -527,6 +526,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