Skip to content

[libc++][test] Make EvilContainer a sequence container#178626

Merged
frederick-vs-ja merged 1 commit intollvm:mainfrom
frederick-vs-ja:test-less-evil-container
Jan 29, 2026
Merged

[libc++][test] Make EvilContainer a sequence container#178626
frederick-vs-ja merged 1 commit intollvm:mainfrom
frederick-vs-ja:test-less-evil-container

Conversation

@frederick-vs-ja
Copy link
Contributor

In tests for flat container adaptors, the EvilContainer type doesn't have sufficient constructors to meet the requirements for sequence containers ([sequence.reqmts]). Also, assignment from an initializer_list doesn't have correct return type.

This patch makes EvilContainer inherit constructors from vector<int> and add a correct assignment operator from initializer_list<int>.

Fixes #178624.

In tests for flat container adaptors, the `EvilContainer` type doesn't
have sufficient constructors to meet the requirements for
sequence containers (sequence.reqmts). Also, assignment from an
`initializer_list` doesn't have correct return type.

This patch make `EvilContainer` inherit constructors from `vector<int>`
and add a correct assignment operator from `initializer_list<int>`.
@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner January 29, 2026 10:30
@frederick-vs-ja frederick-vs-ja added libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. test-suite labels Jan 29, 2026
@llvmbot
Copy link
Member

llvmbot commented Jan 29, 2026

@llvm/pr-subscribers-libcxx

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

Changes

In tests for flat container adaptors, the EvilContainer type doesn't have sufficient constructors to meet the requirements for sequence containers ([sequence.reqmts]). Also, assignment from an initializer_list doesn't have correct return type.

This patch makes EvilContainer inherit constructors from vector&lt;int&gt; and add a correct assignment operator from initializer_list&lt;int&gt;.

Fixes #178624.


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

4 Files Affected:

  • (modified) libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_exceptions.pass.cpp (+7)
  • (modified) libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/move_exceptions.pass.cpp (+7)
  • (modified) libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.cons/move.pass.cpp (+7)
  • (modified) libcxx/test/std/containers/container.adaptors/flat.set/flat.set.cons/move.pass.cpp (+7)
diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_exceptions.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_exceptions.pass.cpp
index cb7e30c2b74fa..e56cb12d9a113 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_exceptions.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_exceptions.pass.cpp
@@ -27,6 +27,8 @@
 static int countdown = 0;
 
 struct EvilContainer : std::vector<int> {
+  using std::vector<int>::vector;
+
   EvilContainer() = default;
   EvilContainer(EvilContainer&& rhs) {
     // Throw on move-construction.
@@ -36,6 +38,11 @@ struct EvilContainer : std::vector<int> {
       throw 42;
     }
   }
+
+  EvilContainer& operator=(std::initializer_list<int> il) {
+    std::vector<int>::operator=(il);
+    return *this;
+  }
 };
 
 int main(int, char**) {
diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/move_exceptions.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/move_exceptions.pass.cpp
index c2085e32be532..44b6e93114c78 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/move_exceptions.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/move_exceptions.pass.cpp
@@ -27,6 +27,8 @@
 static int countdown = 0;
 
 struct EvilContainer : std::vector<int> {
+  using std::vector<int>::vector;
+
   EvilContainer() = default;
   EvilContainer(EvilContainer&& rhs) {
     // Throw on move-construction.
@@ -36,6 +38,11 @@ struct EvilContainer : std::vector<int> {
       throw 42;
     }
   }
+
+  EvilContainer& operator=(std::initializer_list<int> il) {
+    std::vector<int>::operator=(il);
+    return *this;
+  }
 };
 
 int main(int, char**) {
diff --git a/libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.cons/move.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.cons/move.pass.cpp
index 064baa98d2b51..f9fea737254d3 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.cons/move.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.multiset/flat.multiset.cons/move.pass.cpp
@@ -159,6 +159,8 @@ void test_move_noexcept() {
 static int countdown = 0;
 
 struct EvilContainer : std::vector<int> {
+  using std::vector<int>::vector;
+
   EvilContainer() = default;
   EvilContainer(EvilContainer&& rhs) {
     // Throw on move-construction.
@@ -168,6 +170,11 @@ struct EvilContainer : std::vector<int> {
       throw 42;
     }
   }
+
+  EvilContainer& operator=(std::initializer_list<int> il) {
+    std::vector<int>::operator=(il);
+    return *this;
+  }
 };
 
 void test_move_exception() {
diff --git a/libcxx/test/std/containers/container.adaptors/flat.set/flat.set.cons/move.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.set/flat.set.cons/move.pass.cpp
index b737a5fba056d..1d7a3589cc109 100644
--- a/libcxx/test/std/containers/container.adaptors/flat.set/flat.set.cons/move.pass.cpp
+++ b/libcxx/test/std/containers/container.adaptors/flat.set/flat.set.cons/move.pass.cpp
@@ -150,6 +150,8 @@ constexpr bool test() {
 static int countdown = 0;
 
 struct EvilContainer : std::vector<int> {
+  using std::vector<int>::vector;
+
   EvilContainer() = default;
   EvilContainer(EvilContainer&& rhs) {
     // Throw on move-construction.
@@ -159,6 +161,11 @@ struct EvilContainer : std::vector<int> {
       throw 42;
     }
   }
+
+  EvilContainer& operator=(std::initializer_list<int> il) {
+    std::vector<int>::operator=(il);
+    return *this;
+  }
 };
 
 void test_move_exception() {

@frederick-vs-ja frederick-vs-ja merged commit a1c81b0 into llvm:main Jan 29, 2026
84 checks passed
@frederick-vs-ja frederick-vs-ja deleted the test-less-evil-container branch January 29, 2026 23:43
honeygoyal pushed a commit to honeygoyal/llvm-project that referenced this pull request Jan 30, 2026
In tests for flat container adaptors, the `EvilContainer` type doesn't
have sufficient constructors to meet the requirements for sequence
containers ([sequence.reqmts]). Also, assignment from an
`initializer_list` doesn't have correct return type.

This patch makes `EvilContainer` inherit constructors from `vector<int>`
and add a correct assignment operator from `initializer_list<int>`.
sshrestha-aa pushed a commit to sshrestha-aa/llvm-project that referenced this pull request Feb 4, 2026
In tests for flat container adaptors, the `EvilContainer` type doesn't
have sufficient constructors to meet the requirements for sequence
containers ([sequence.reqmts]). Also, assignment from an
`initializer_list` doesn't have correct return type.

This patch makes `EvilContainer` inherit constructors from `vector<int>`
and add a correct assignment operator from `initializer_list<int>`.
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.

[libc++][test] flat_set tests have an EvilContainer that's too evil

3 participants