Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc++] Refactor tests for hijacked address operator in vector #117457

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ldionne
Copy link
Member

@ldionne ldionne commented Nov 24, 2024

No description provided.

@ldionne ldionne requested a review from a team as a code owner November 24, 2024 01:05
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Nov 24, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 24, 2024

@llvm/pr-subscribers-libcxx

Author: Louis Dionne (ldionne)

Changes

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

12 Files Affected:

  • (added) libcxx/test/std/containers/sequences/vector/addressof.compile.pass.cpp (+47)
  • (removed) libcxx/test/std/containers/sequences/vector/vector.cons/assign_copy.addressof.compile.pass.cpp (-24)
  • (removed) libcxx/test/std/containers/sequences/vector/vector.cons/assign_move.addressof.compile.pass.cpp (-25)
  • (removed) libcxx/test/std/containers/sequences/vector/vector.cons/move.addressof.compile.pass.cpp (-32)
  • (removed) libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace.addressof.compile.pass.cpp (-25)
  • (removed) libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter.addressof.compile.pass.cpp (-23)
  • (removed) libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter.addressof.compile.pass.cpp (-23)
  • (removed) libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.addressof.compile.pass.cpp (-31)
  • (removed) libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.addressof.compile.pass.cpp (-25)
  • (removed) libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_size_value.addressof.compile.pass.cpp (-24)
  • (removed) libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_value.addressof.compile.pass.cpp (-24)
  • (removed) libcxx/test/std/containers/sequences/vector/vector.special/swap.addressof.compile.pass.cpp (-25)
diff --git a/libcxx/test/std/containers/sequences/vector/addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/vector/addressof.compile.pass.cpp
new file mode 100644
index 00000000000000..120b7b289af93e
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/vector/addressof.compile.pass.cpp
@@ -0,0 +1,47 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03 && !stdlib=libc++
+
+// <vector>
+
+// Validate various member functions of std::vector with an ADL-hijacking operator&
+
+#include <vector>
+#include <utility>
+
+#include "operator_hijacker.h"
+#include "test_iterators.h"
+
+using Vector = std::vector<operator_hijacker>;
+
+void test(
+    Vector v, Vector::const_iterator it, cpp17_input_iterator<operator_hijacker*> other_it, operator_hijacker val) {
+  // emplace / insert
+  v.emplace(it);
+  v.insert(it, it, it);
+  v.insert(it, other_it, other_it);
+  v.insert(it, operator_hijacker());
+  v.insert(it, 1, val);
+  v.insert(it, val);
+
+  // erase
+  v.erase(it);
+  v.erase(it, it);
+
+  // assignment
+  v = static_cast<Vector&>(v);
+  v = std::move(v);
+
+  // construction
+  { Vector v2(std::move(v)); }
+  { Vector v2(std::move(v), std::allocator<operator_hijacker>()); }
+
+  // swap
+  v.swap(v);
+}
diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/assign_copy.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/assign_copy.addressof.compile.pass.cpp
deleted file mode 100644
index ceecdfda3fa304..00000000000000
--- a/libcxx/test/std/containers/sequences/vector/vector.cons/assign_copy.addressof.compile.pass.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// <vector>
-
-// vector& operator=(const vector& c);
-
-// Validate whether the container can be copy-assigned with an ADL-hijacking operator&
-
-#include <vector>
-
-#include "test_macros.h"
-#include "operator_hijacker.h"
-
-void test() {
-  std::vector<operator_hijacker> vo;
-  std::vector<operator_hijacker> v;
-  v = vo;
-}
diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/assign_move.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/assign_move.addressof.compile.pass.cpp
deleted file mode 100644
index 2008c8d048f4b4..00000000000000
--- a/libcxx/test/std/containers/sequences/vector/vector.cons/assign_move.addressof.compile.pass.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// <vector>
-
-// vector& operator=(vector&& c);
-
-// Validate whether the container can be copy-assigned with an ADL-hijacking operator&
-
-#include <vector>
-#include <utility>
-
-#include "test_macros.h"
-#include "operator_hijacker.h"
-
-void test() {
-  std::vector<operator_hijacker> vo;
-  std::vector<operator_hijacker> v;
-  v = std::move(vo);
-}
diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/move.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/move.addressof.compile.pass.cpp
deleted file mode 100644
index 521b8705d49202..00000000000000
--- a/libcxx/test/std/containers/sequences/vector/vector.cons/move.addressof.compile.pass.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// UNSUPPORTED: c++03 && !stdlib=libc++
-
-// <vector>
-
-// vector(vector&& c);
-
-// Validate whether the container can be copy-assigned with an ADL-hijacking operator&
-
-#include <vector>
-#include <utility>
-
-#include "test_macros.h"
-#include "operator_hijacker.h"
-
-void test() {
-  {
-    std::vector<operator_hijacker> vo;
-    std::vector<operator_hijacker> v(std::move(vo));
-  }
-  {
-    std::vector<operator_hijacker> vo;
-    std::vector<operator_hijacker> v(std::move(vo), std::allocator<operator_hijacker>());
-  }
-}
diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace.addressof.compile.pass.cpp
deleted file mode 100644
index 43e553e71e7414..00000000000000
--- a/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace.addressof.compile.pass.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// UNSUPPORTED: c++03 && !stdlib=libc++
-
-// <vector>
-
-// template <class... Args> iterator emplace(const_iterator pos, Args&&... args);
-
-// Validate whether the container can be copy-assigned with an ADL-hijacking operator&
-
-#include <vector>
-
-#include "test_macros.h"
-#include "operator_hijacker.h"
-
-void test() {
-  std::vector<operator_hijacker> v;
-  v.emplace(v.end());
-}
diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter.addressof.compile.pass.cpp
deleted file mode 100644
index 0fce3498fec7e8..00000000000000
--- a/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter.addressof.compile.pass.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// <vector>
-
-// iterator erase(const_iterator position);
-
-// Validate whether the container can be copy-assigned with an ADL-hijacking operator&
-
-#include <vector>
-
-#include "test_macros.h"
-#include "operator_hijacker.h"
-
-void test() {
-  std::vector<operator_hijacker> v;
-  v.erase(v.end());
-}
diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter.addressof.compile.pass.cpp
deleted file mode 100644
index bc90fa783e98f5..00000000000000
--- a/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter.addressof.compile.pass.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// <vector>
-
-// iterator erase(const_iterator position);
-
-// Validate whether the container can be copy-assigned with an ADL-hijacking operator&
-
-#include <vector>
-
-#include "test_macros.h"
-#include "operator_hijacker.h"
-
-void test() {
-  std::vector<operator_hijacker> v;
-  v.erase(v.begin(), v.end());
-}
diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.addressof.compile.pass.cpp
deleted file mode 100644
index f8311090b37e3c..00000000000000
--- a/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.addressof.compile.pass.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// <vector>
-
-// template <class Iter>
-//   iterator insert(const_iterator position, Iter first, Iter last);
-
-// Validate whether the container can be copy-assigned with an ADL-hijacking operator&
-
-#include <vector>
-
-#include "test_macros.h"
-#include "operator_hijacker.h"
-#include "test_iterators.h"
-
-void test(cpp17_input_iterator<operator_hijacker*> i) {
-  {
-    std::vector<operator_hijacker> v;
-    v.insert(v.end(), i, i);
-  }
-  {
-    std::vector<operator_hijacker> v;
-    v.insert(v.end(), v.begin(), v.end());
-  }
-}
diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.addressof.compile.pass.cpp
deleted file mode 100644
index 11f24604eeac4d..00000000000000
--- a/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.addressof.compile.pass.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// UNSUPPORTED: c++03 && !stdlib=libc++
-
-// <vector>
-
-// iterator insert(const_iterator position, value_type&& x);
-
-// Validate whether the container can be copy-assigned with an ADL-hijacking operator&
-
-#include <vector>
-
-#include "test_macros.h"
-#include "operator_hijacker.h"
-
-void test() {
-  std::vector<operator_hijacker> v;
-  v.insert(v.end(), operator_hijacker());
-}
diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_size_value.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_size_value.addressof.compile.pass.cpp
deleted file mode 100644
index c02b92a4998e85..00000000000000
--- a/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_size_value.addressof.compile.pass.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// <vector>
-
-// iterator insert(const_iterator position, size_type n, const value_type& x);
-
-// Validate whether the container can be copy-assigned with an ADL-hijacking operator&
-
-#include <vector>
-
-#include "test_macros.h"
-#include "operator_hijacker.h"
-
-void test() {
-  std::vector<operator_hijacker> v;
-  operator_hijacker val;
-  v.insert(v.end(), 1, val);
-}
diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_value.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_value.addressof.compile.pass.cpp
deleted file mode 100644
index fbf1a4f50b974f..00000000000000
--- a/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_value.addressof.compile.pass.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// <vector>
-
-// iterator insert(const_iterator position, const value_type& x);
-
-// Validate whether the container can be copy-assigned with an ADL-hijacking operator&
-
-#include <vector>
-
-#include "test_macros.h"
-#include "operator_hijacker.h"
-
-void test() {
-  std::vector<operator_hijacker> v;
-  operator_hijacker val;
-  v.insert(v.end(), val);
-}
diff --git a/libcxx/test/std/containers/sequences/vector/vector.special/swap.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.special/swap.addressof.compile.pass.cpp
deleted file mode 100644
index 4e908d9ff6eaca..00000000000000
--- a/libcxx/test/std/containers/sequences/vector/vector.special/swap.addressof.compile.pass.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// <vector>
-
-// template <class T, class Alloc>
-//   void swap(vector<T,Alloc>& x, vector<T,Alloc>& y);
-
-// Validate whether the container can be copy-assigned with an ADL-hijacking operator&
-
-#include <vector>
-
-#include "test_macros.h"
-#include "operator_hijacker.h"
-
-void test() {
-  std::vector<operator_hijacker> vo;
-  std::vector<operator_hijacker> v;
-  v.swap(vo);
-}

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants