diff mbox series

[pushed] c++: Add new std::move test [PR67906]

Message ID 20220817194616.1642511-1-polacek@redhat.com
State New
Headers show
Series [pushed] c++: Add new std::move test [PR67906] | expand

Commit Message

Marek Polacek Aug. 17, 2022, 7:46 p.m. UTC
As discussed in 67906, let's make sure we don't warn about a std::move
when initializing when there's a T(const T&&) ctor.

Tested x86_64-pc-linux-gnu, applying to trunk.

	PR c++/67906

gcc/testsuite/ChangeLog:

	* g++.dg/cpp0x/Wredundant-move11.C: New test.
---
 .../g++.dg/cpp0x/Wredundant-move11.C          | 32 +++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/Wredundant-move11.C


base-commit: 5adfb6540db95da5faf1f77fbe9ec38b4cf8eb1f
diff mbox series

Patch

diff --git a/gcc/testsuite/g++.dg/cpp0x/Wredundant-move11.C b/gcc/testsuite/g++.dg/cpp0x/Wredundant-move11.C
new file mode 100644
index 00000000000..5dfa37f1686
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/Wredundant-move11.C
@@ -0,0 +1,32 @@ 
+// PR c++/67906
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wall -Wextra" }
+
+// Define std::move.
+namespace std {
+  template<typename _Tp>
+    struct remove_reference
+    { typedef _Tp   type; };
+
+  template<typename _Tp>
+    struct remove_reference<_Tp&>
+    { typedef _Tp   type; };
+
+  template<typename _Tp>
+    struct remove_reference<_Tp&&>
+    { typedef _Tp   type; };
+
+  template<typename _Tp>
+    constexpr typename std::remove_reference<_Tp>::type&&
+    move(_Tp&& __t) noexcept
+    { return static_cast<typename std::remove_reference<_Tp>::type&&>(__t); }
+}
+
+struct X {
+  X() { }
+  X(const X&) { }
+  X(const X&&) { }
+};
+
+const X x;
+const X y = std::move(x);