Skip to content

Conversation

@frederick-vs-ja
Copy link
Contributor

@frederick-vs-ja frederick-vs-ja commented Apr 8, 2025

Some test files for flat container adaptors redundantly include <iostream> and, surprisingly, <cstddef>. This patch removes the redundant inclusions.

Inclusions of <vector> is also removed since a sane implementation is expected to make instantiation of flat_(multi)map<K, V> or flat_(multi)set<K> valid when only <flat_map> or <flat_set> is included.

Some test files for flat container adaptors redundantly include
`<iostream>`. This patch removes the redundant inclusions.
@frederick-vs-ja frederick-vs-ja added libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. test-suite labels Apr 8, 2025
@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner April 8, 2025 03:42
@llvmbot
Copy link
Member

llvmbot commented Apr 8, 2025

@llvm/pr-subscribers-libcxx

Author: A. Jiang (frederick-vs-ja)

Changes

Some test files for flat container adaptors redundantly include &lt;iostream&gt;. This patch removes the redundant inclusions.


Full diff: https://github.com/llvm/llvm-project/pull/134776.diff

4 Files Affected:

  • (modified) libcxx/test/std/containers/container.adaptors/flat.map/flat.map.iterators/reverse_iterator.pass.cpp (-1)
  • (modified) libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.iterators/reverse_iterator.pass.cpp (-1)
  • (modified) libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.iterators/reverse_iterator.pass.cpp (-1)
  • (modified) libcxx/test/std/containers/container.adaptors/flat.set/flat.set.iterators/reverse_iterator.pass.cpp (-1)
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.iterators/reverse_iterator.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.iterators/reverse_iterator.pass.cpp
index fc3949d70745f..7a111e228c115 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.iterators/reverse_iterator.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.iterators/reverse_iterator.pass.cpp
@@ -28,7 +28,6 @@
 #include <iterator>
 
 #include "test_macros.h"
-#include <iostream>
 
 int main(int, char**) {
   {
diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.iterators/reverse_iterator.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.iterators/reverse_iterator.pass.cpp
index 8c1e5451f703f..35b2b9f8a9e7e 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.iterators/reverse_iterator.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.iterators/reverse_iterator.pass.cpp
@@ -30,7 +30,6 @@
 #include <iterator>
 
 #include "test_macros.h"
-#include <iostream>
 
 int main(int, char**) {
   {
diff --git a/libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.iterators/reverse_iterator.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.iterators/reverse_iterator.pass.cpp
index 9d443ef8784e2..76bd49b4abd9e 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.iterators/reverse_iterator.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.iterators/reverse_iterator.pass.cpp
@@ -28,7 +28,6 @@
 #include <iterator>
 
 #include "test_macros.h"
-#include <iostream>
 
 void test() {
   {
diff --git a/libcxx/test/std/containers/container.adaptors/flat.set/flat.set.iterators/reverse_iterator.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.set/flat.set.iterators/reverse_iterator.pass.cpp
index d1e4cef3de19e..a9ef87d483e6f 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.set/flat.set.iterators/reverse_iterator.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.set/flat.set.iterators/reverse_iterator.pass.cpp
@@ -28,7 +28,6 @@
 #include <iterator>
 
 #include "test_macros.h"
-#include <iostream>
 
 void test() {
   {

#include <iterator>

#include "test_macros.h"
#include <iostream>
Copy link
Contributor

Choose a reason for hiding this comment

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

The <vector> and <iterator> includes above seem to be unused as well. Probably also the case in the other tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is somehow tricky. These files don't explicitly write vector but implicitly use vector<T> as default template arguments. Likewise, the reverse iterator types are reverse_iterator specializations, which are guaranteed to be provided in <iterator>.

Copy link
Contributor

Choose a reason for hiding this comment

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

We have to provide these things though <flat_map>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I found that these files use std::distance, which is only guaranteed to be available in <iterator> and <ranges>, although transitively introduced by several headers in libc++.

I think we should either keep includes of <iterator> or replace these std::distance calls with operator-.

Copy link
Contributor

Choose a reason for hiding this comment

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

When they're used we can keep them.

@llvmbot
Copy link
Member

llvmbot commented Apr 8, 2025

/cherry-pick 4ab86ed

Error: Command failed due to missing milestone.

#include <iterator>

#include "test_macros.h"
#include <iostream>
Copy link
Contributor

Choose a reason for hiding this comment

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

When they're used we can keep them.

@frederick-vs-ja frederick-vs-ja merged commit 5c45e23 into llvm:main Apr 13, 2025
80 checks passed
@frederick-vs-ja frederick-vs-ja deleted the libcxx-test-iostream-redux branch April 13, 2025 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. test-suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants