Преглед на файлове

AK: Move move() into the "std" namespace

This makes GCC emit warnings about redundant and pessimizing moves.
It also allows static analyzers like clang-tidy to detect common bugs
like use-after-move.
Andreas Kling преди 4 години
родител
ревизия
ea81dc13cf
променени са 1 файла, в които са добавени 15 реда и са изтрити 8 реда
  1. 15 8
      AK/StdLibExtras.h

+ 15 - 8
AK/StdLibExtras.h

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  * All rights reserved.
  * All rights reserved.
  *
  *
  * Redistribution and use in source and binary forms, with or without
  * Redistribution and use in source and binary forms, with or without
@@ -33,6 +33,20 @@ constexpr unsigned round_up_to_power_of_two(unsigned value, unsigned power_of_tw
     return ((value - 1) & ~(power_of_two - 1)) + power_of_two;
     return ((value - 1) & ~(power_of_two - 1)) + power_of_two;
 }
 }
 
 
+namespace std {
+
+// NOTE: This is in the "std" namespace since some compiler features rely on it.
+
+template<typename T>
+constexpr T&& move(T& arg)
+{
+    return static_cast<T&&>(arg);
+}
+
+}
+
+using std::move;
+
 namespace AK {
 namespace AK {
 
 
 template<typename T>
 template<typename T>
@@ -77,12 +91,6 @@ constexpr T ceil_div(T a, U b)
     return result;
     return result;
 }
 }
 
 
-template<typename T>
-constexpr T&& move(T& arg)
-{
-    return static_cast<T&&>(arg);
-}
-
 template<typename T, typename U>
 template<typename T, typename U>
 inline void swap(T& a, U& b)
 inline void swap(T& a, U& b)
 {
 {
@@ -622,7 +630,6 @@ using AK::MakeSigned;
 using AK::MakeUnsigned;
 using AK::MakeUnsigned;
 using AK::max;
 using AK::max;
 using AK::min;
 using AK::min;
-using AK::move;
 using AK::RemoveConst;
 using AK::RemoveConst;
 using AK::swap;
 using AK::swap;
 using AK::UnderlyingType;
 using AK::UnderlyingType;