Skip to content

include/container_ios: include <ostream>, not <iosfwd> - #72479

Merged
idryomov merged 1 commit into
ceph:mainfrom
dvanders:wip-container-ios-ostream
Oct 9, 2026
Merged

idryomov merged 1 commit into
ceph:mainfrom
dvanders:wip-container-ios-ostream

Conversation

@dvanders

@dvanders dvanders commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

include/container_ios.h defines operator<< overloads on std::ostream but only includes <iosfwd>. libstdc++ and older libc++ pull <ostream> in through <iomanip>; newer libc++ doesn't, and librbd/ConfigWatcher.cc fails on macOS:

container_ios.h:95:7: error: invalid operands to binary expression
('std::ostream' (aka 'basic_ostream<char>') and 'const char[2]')

Reproduced with Apple clang 21 and -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES on a file that includes only this header; including <ostream> fixes it. Reported by @bstillwell while building the macOS series.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)

🤖 Generated with Claude Code

@dvanders

dvanders commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test api

Comment thread src/include/container_ios.h Resolved
@dvanders
dvanders force-pushed the wip-container-ios-ostream branch from 1abb64a to 396b461 Compare October 8, 2026 04:58

@MaxKellermann MaxKellermann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct fix, this was a mistake in my header cleanup PR.
Agree with @tchaikov, <iomanip> should be dropped as well. (Even if some other source gets it only through this header, then that other source is buggy and must be fixed.)

@MaxKellermann

Copy link
Copy Markdown
Member

Even if some other source gets it only through this header, then that other source is buggy and must be fixed.)

 /ceph/src/common/frag.cc:50:76: error: no member named 'setfill' in namespace 'std'
07:06:19     50 |       std::cerr << "correcting byte swapped frag_t(0x" << std::hex << std::setfill('0') << std::setw(8) << _enc
07:06:19        |                                                                       ~~~~~^

And of course, such (old) bugs do exist.
@dvanders I can submit a new PR to fix these bugs - or do you want to add fixes to your PR?

@MaxKellermann

Copy link
Copy Markdown
Member

This kind of bug is difficult to reproduce with GCC because of libstdc++'s many internal header dependencies; I tried chmod 600 /usr/include/c++/14/iomanip:

In file included from /usr/include/c++/14/chrono:3360,
                 from /home/max/git/ceph-main/src/include/encoding.h:33,
                 from /home/max/git/ceph-main/src/include/compact_map.h:16,
                 from /home/max/git/ceph-main/src/include/frag.h:28,
                 from /home/max/git/ceph-main/src/common/frag.cc:16:
/usr/include/c++/14/bits/chrono_io.h:38:10: fatal error: /usr/include/c++/14/iomanip: Permission denied
   38 | #include <iomanip> // setw, setfill
      |          ^~~~~~~~~

If you have <chrono>, you implicitly get <iomanip>, too. Sigh. What a mess.
How I wish C++ modules had been a good technology and everybody would use them...

@tchaikov

tchaikov commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

How I wish C++ modules had been a good technology and everybody would use them...

agreed. i think it just takes time to get the ecosystem (the tooling and libraries) mature enough and the distros to pickup these the toolings and libraries.

The operator<< overloads here write to std::ostream, so the header needs its
full definition. libstdc++ and older libc++ happen to pull <ostream> in
through <iomanip>; libc++ without those transitive includes does not, and
librbd/ConfigWatcher.cc fails on macOS with:

  container_ios.h:95:7: error: invalid operands to binary expression
  ('std::ostream' (aka 'basic_ostream<char>') and 'const char[2]')

The header has been like this since cf432cc moved these functions out
of include/types.h.

Keep <iomanip> for now: nothing here uses a manipulator, but files such as
common/frag.cc still get it only through this header.

Reported-by: Bryan Stillwell <[email protected]>
Assisted-by: Claude-Code-v2.1.294:claude-opus-5-5
Signed-off-by: Dan van der Ster <[email protected]>
@dvanders
dvanders force-pushed the wip-container-ios-ostream branch from 396b461 to 3228c75 Compare October 8, 2026 17:28
@dvanders

dvanders commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Keeping this one open rather than closing it in favour of #72481: this PR only swaps <iosfwd> for <ostream> and keeps <iomanip>, so it fixes the libc++ build without changing what other files get transitively. It is approved and green.

Dropping <iomanip> is still right, but as tchaikov's build on #72481 shows (cephfs_mirror/PeerReplayer.cc, and common/frag.cc before it), some files rely on getting it from this header. Suggest this merges as the minimal fix, and #72481 rebases on it to do the <iomanip> cleanup together with fixes for those files.

@idryomov
idryomov merged commit 84f6ab6 into ceph:main Oct 9, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants