Pārlūkot izejas kodu

AK: Remove experimental clang -Wconsumed stuff

This stopped working quite some time ago due to Clang losing track of
typestates for some reason and everything becoming "unknown".

Since we're primarily using GCC anyway, it doesn't seem worth it to try
and maintain this non-working experiment for a secondary compiler.

Also it doesn't look like the Clang team is actively maintaining this
flag anyway. So good-bye, -Wconsumed. :/
Andreas Kling 5 gadi atpakaļ
vecāks
revīzija
76bcd284f9
5 mainītis faili ar 5 papildinājumiem un 66 dzēšanām
  1. 1 16
      AK/NonnullOwnPtr.h
  2. 2 21
      AK/NonnullRefPtr.h
  3. 1 13
      AK/Optional.h
  4. 0 13
      AK/Platform.h
  5. 1 3
      CMakeLists.txt

+ 1 - 16
AK/NonnullOwnPtr.h

@@ -42,25 +42,22 @@ template<typename T>
 class WeakPtr;
 class WeakPtr;
 
 
 template<typename T>
 template<typename T>
-class CONSUMABLE(unconsumed) NonnullOwnPtr {
+class NonnullOwnPtr {
 public:
 public:
     typedef T ElementType;
     typedef T ElementType;
 
 
     enum AdoptTag { Adopt };
     enum AdoptTag { Adopt };
 
 
-    RETURN_TYPESTATE(unconsumed)
     NonnullOwnPtr(AdoptTag, T& ptr)
     NonnullOwnPtr(AdoptTag, T& ptr)
         : m_ptr(&ptr)
         : m_ptr(&ptr)
     {
     {
     }
     }
-    RETURN_TYPESTATE(unconsumed)
     NonnullOwnPtr(NonnullOwnPtr&& other)
     NonnullOwnPtr(NonnullOwnPtr&& other)
         : m_ptr(other.leak_ptr())
         : m_ptr(other.leak_ptr())
     {
     {
         ASSERT(m_ptr);
         ASSERT(m_ptr);
     }
     }
     template<typename U>
     template<typename U>
-    RETURN_TYPESTATE(unconsumed)
     NonnullOwnPtr(NonnullOwnPtr<U>&& other)
     NonnullOwnPtr(NonnullOwnPtr<U>&& other)
         : m_ptr(other.leak_ptr())
         : m_ptr(other.leak_ptr())
     {
     {
@@ -97,7 +94,6 @@ public:
     template<typename U>
     template<typename U>
     NonnullOwnPtr& operator=(const WeakPtr<U>&) = delete;
     NonnullOwnPtr& operator=(const WeakPtr<U>&) = delete;
 
 
-    RETURN_TYPESTATE(unconsumed)
     NonnullOwnPtr& operator=(NonnullOwnPtr&& other)
     NonnullOwnPtr& operator=(NonnullOwnPtr&& other)
     {
     {
         NonnullOwnPtr ptr(move(other));
         NonnullOwnPtr ptr(move(other));
@@ -106,7 +102,6 @@ public:
     }
     }
 
 
     template<typename U>
     template<typename U>
-    RETURN_TYPESTATE(unconsumed)
     NonnullOwnPtr& operator=(NonnullOwnPtr<U>&& other)
     NonnullOwnPtr& operator=(NonnullOwnPtr<U>&& other)
     {
     {
         NonnullOwnPtr ptr(move(other));
         NonnullOwnPtr ptr(move(other));
@@ -114,31 +109,21 @@ public:
         return *this;
         return *this;
     }
     }
 
 
-    CALLABLE_WHEN(unconsumed)
-    SET_TYPESTATE(consumed)
     T* leak_ptr()
     T* leak_ptr()
     {
     {
         return exchange(m_ptr, nullptr);
         return exchange(m_ptr, nullptr);
     }
     }
 
 
-    CALLABLE_WHEN(unconsumed)
     T* ptr() { return m_ptr; }
     T* ptr() { return m_ptr; }
-    CALLABLE_WHEN(unconsumed)
     const T* ptr() const { return m_ptr; }
     const T* ptr() const { return m_ptr; }
 
 
-    CALLABLE_WHEN(unconsumed)
     T* operator->() { return m_ptr; }
     T* operator->() { return m_ptr; }
-    CALLABLE_WHEN(unconsumed)
     const T* operator->() const { return m_ptr; }
     const T* operator->() const { return m_ptr; }
 
 
-    CALLABLE_WHEN(unconsumed)
     T& operator*() { return *m_ptr; }
     T& operator*() { return *m_ptr; }
-    CALLABLE_WHEN(unconsumed)
     const T& operator*() const { return *m_ptr; }
     const T& operator*() const { return *m_ptr; }
 
 
-    CALLABLE_WHEN(unconsumed)
     operator const T*() const { return m_ptr; }
     operator const T*() const { return m_ptr; }
-    CALLABLE_WHEN(unconsumed)
     operator T*() { return m_ptr; }
     operator T*() { return m_ptr; }
 
 
     operator bool() const = delete;
     operator bool() const = delete;

+ 2 - 21
AK/NonnullRefPtr.h

@@ -53,49 +53,42 @@ inline void unref_if_not_null(T* ptr)
 }
 }
 
 
 template<typename T>
 template<typename T>
-class CONSUMABLE(unconsumed) NonnullRefPtr {
+class NonnullRefPtr {
 public:
 public:
     typedef T ElementType;
     typedef T ElementType;
 
 
     enum AdoptTag { Adopt };
     enum AdoptTag { Adopt };
 
 
-    RETURN_TYPESTATE(unconsumed)
     NonnullRefPtr(const T& object)
     NonnullRefPtr(const T& object)
         : m_ptr(const_cast<T*>(&object))
         : m_ptr(const_cast<T*>(&object))
     {
     {
         m_ptr->ref();
         m_ptr->ref();
     }
     }
     template<typename U>
     template<typename U>
-    RETURN_TYPESTATE(unconsumed)
     NonnullRefPtr(const U& object)
     NonnullRefPtr(const U& object)
         : m_ptr(&const_cast<U&>(object))
         : m_ptr(&const_cast<U&>(object))
     {
     {
         m_ptr->ref();
         m_ptr->ref();
     }
     }
-    RETURN_TYPESTATE(unconsumed)
     NonnullRefPtr(AdoptTag, T& object)
     NonnullRefPtr(AdoptTag, T& object)
         : m_ptr(&object)
         : m_ptr(&object)
     {
     {
     }
     }
-    RETURN_TYPESTATE(unconsumed)
     NonnullRefPtr(NonnullRefPtr&& other)
     NonnullRefPtr(NonnullRefPtr&& other)
         : m_ptr(&other.leak_ref())
         : m_ptr(&other.leak_ref())
     {
     {
     }
     }
     template<typename U>
     template<typename U>
-    RETURN_TYPESTATE(unconsumed)
     NonnullRefPtr(NonnullRefPtr<U>&& other)
     NonnullRefPtr(NonnullRefPtr<U>&& other)
         : m_ptr(&other.leak_ref())
         : m_ptr(&other.leak_ref())
     {
     {
     }
     }
-    RETURN_TYPESTATE(unconsumed)
     NonnullRefPtr(const NonnullRefPtr& other)
     NonnullRefPtr(const NonnullRefPtr& other)
         : m_ptr(const_cast<T*>(other.ptr()))
         : m_ptr(const_cast<T*>(other.ptr()))
     {
     {
         m_ptr->ref();
         m_ptr->ref();
     }
     }
     template<typename U>
     template<typename U>
-    RETURN_TYPESTATE(unconsumed)
     NonnullRefPtr(const NonnullRefPtr<U>& other)
     NonnullRefPtr(const NonnullRefPtr<U>& other)
         : m_ptr(const_cast<U*>(other.ptr()))
         : m_ptr(const_cast<U*>(other.ptr()))
     {
     {
@@ -162,73 +155,61 @@ public:
         return *this;
         return *this;
     }
     }
 
 
-    [[nodiscard]] CALLABLE_WHEN(unconsumed)
-        SET_TYPESTATE(consumed)
-            T& leak_ref()
+    [[nodiscard]] T& leak_ref()
     {
     {
         ASSERT(m_ptr);
         ASSERT(m_ptr);
         return *exchange(m_ptr, nullptr);
         return *exchange(m_ptr, nullptr);
     }
     }
 
 
-    CALLABLE_WHEN("unconsumed", "unknown")
     T* ptr()
     T* ptr()
     {
     {
         ASSERT(m_ptr);
         ASSERT(m_ptr);
         return m_ptr;
         return m_ptr;
     }
     }
-    CALLABLE_WHEN("unconsumed", "unknown")
     const T* ptr() const
     const T* ptr() const
     {
     {
         ASSERT(m_ptr);
         ASSERT(m_ptr);
         return m_ptr;
         return m_ptr;
     }
     }
 
 
-    CALLABLE_WHEN(unconsumed)
     T* operator->()
     T* operator->()
     {
     {
         ASSERT(m_ptr);
         ASSERT(m_ptr);
         return m_ptr;
         return m_ptr;
     }
     }
-    CALLABLE_WHEN(unconsumed)
     const T* operator->() const
     const T* operator->() const
     {
     {
         ASSERT(m_ptr);
         ASSERT(m_ptr);
         return m_ptr;
         return m_ptr;
     }
     }
 
 
-    CALLABLE_WHEN(unconsumed)
     T& operator*()
     T& operator*()
     {
     {
         ASSERT(m_ptr);
         ASSERT(m_ptr);
         return *m_ptr;
         return *m_ptr;
     }
     }
-    CALLABLE_WHEN(unconsumed)
     const T& operator*() const
     const T& operator*() const
     {
     {
         ASSERT(m_ptr);
         ASSERT(m_ptr);
         return *m_ptr;
         return *m_ptr;
     }
     }
 
 
-    CALLABLE_WHEN(unconsumed)
     operator T*()
     operator T*()
     {
     {
         ASSERT(m_ptr);
         ASSERT(m_ptr);
         return m_ptr;
         return m_ptr;
     }
     }
-    CALLABLE_WHEN(unconsumed)
     operator const T*() const
     operator const T*() const
     {
     {
         ASSERT(m_ptr);
         ASSERT(m_ptr);
         return m_ptr;
         return m_ptr;
     }
     }
 
 
-    CALLABLE_WHEN(unconsumed)
     operator T&()
     operator T&()
     {
     {
         ASSERT(m_ptr);
         ASSERT(m_ptr);
         return *m_ptr;
         return *m_ptr;
     }
     }
-    CALLABLE_WHEN(unconsumed)
     operator const T&() const
     operator const T&() const
     {
     {
         ASSERT(m_ptr);
         ASSERT(m_ptr);

+ 1 - 13
AK/Optional.h

@@ -34,12 +34,10 @@
 namespace AK {
 namespace AK {
 
 
 template<typename T>
 template<typename T>
-class CONSUMABLE(unknown) alignas(T) Optional {
+class alignas(T) Optional {
 public:
 public:
-    RETURN_TYPESTATE(unknown)
     Optional() {}
     Optional() {}
 
 
-    RETURN_TYPESTATE(unknown)
     Optional(const T& value)
     Optional(const T& value)
         : m_has_value(true)
         : m_has_value(true)
     {
     {
@@ -47,21 +45,18 @@ public:
     }
     }
 
 
     template<typename U>
     template<typename U>
-    RETURN_TYPESTATE(unknown)
     Optional(const U& value)
     Optional(const U& value)
         : m_has_value(true)
         : m_has_value(true)
     {
     {
         new (&m_storage) T(value);
         new (&m_storage) T(value);
     }
     }
 
 
-    RETURN_TYPESTATE(unknown)
     Optional(T&& value)
     Optional(T&& value)
         : m_has_value(true)
         : m_has_value(true)
     {
     {
         new (&m_storage) T(move(value));
         new (&m_storage) T(move(value));
     }
     }
 
 
-    RETURN_TYPESTATE(unknown)
     Optional(Optional&& other)
     Optional(Optional&& other)
         : m_has_value(other.m_has_value)
         : m_has_value(other.m_has_value)
     {
     {
@@ -71,7 +66,6 @@ public:
         }
         }
     }
     }
 
 
-    RETURN_TYPESTATE(unknown)
     Optional(const Optional& other)
     Optional(const Optional& other)
         : m_has_value(other.m_has_value)
         : m_has_value(other.m_has_value)
     {
     {
@@ -80,7 +74,6 @@ public:
         }
         }
     }
     }
 
 
-    RETURN_TYPESTATE(unknown)
     Optional& operator=(const Optional& other)
     Optional& operator=(const Optional& other)
     {
     {
         if (this != &other) {
         if (this != &other) {
@@ -93,7 +86,6 @@ public:
         return *this;
         return *this;
     }
     }
 
 
-    RETURN_TYPESTATE(unknown)
     Optional& operator=(Optional&& other)
     Optional& operator=(Optional&& other)
     {
     {
         if (this != &other) {
         if (this != &other) {
@@ -118,23 +110,19 @@ public:
         }
         }
     }
     }
 
 
-    SET_TYPESTATE(consumed)
     ALWAYS_INLINE bool has_value() const { return m_has_value; }
     ALWAYS_INLINE bool has_value() const { return m_has_value; }
 
 
-    CALLABLE_WHEN(consumed)
     ALWAYS_INLINE T& value()
     ALWAYS_INLINE T& value()
     {
     {
         ASSERT(m_has_value);
         ASSERT(m_has_value);
         return *reinterpret_cast<T*>(&m_storage);
         return *reinterpret_cast<T*>(&m_storage);
     }
     }
 
 
-    CALLABLE_WHEN(consumed)
     ALWAYS_INLINE const T& value() const
     ALWAYS_INLINE const T& value() const
     {
     {
         return value_without_consume_state();
         return value_without_consume_state();
     }
     }
 
 
-    CALLABLE_WHEN(consumed)
     T release_value()
     T release_value()
     {
     {
         ASSERT(m_has_value);
         ASSERT(m_has_value);

+ 0 - 13
AK/Platform.h

@@ -51,19 +51,6 @@
 #endif
 #endif
 #define FLATTEN [[gnu::flatten]]
 #define FLATTEN [[gnu::flatten]]
 
 
-// FIXME: Re-enable this when we can figure out why Clang gets confused about "unknown"
-#if 0
-#    define CONSUMABLE(initial_state) __attribute__((consumable(initial_state)))
-#    define CALLABLE_WHEN(...) __attribute__((callable_when(__VA_ARGS__)))
-#    define SET_TYPESTATE(state) __attribute__((set_typestate(state)))
-#    define RETURN_TYPESTATE(state) __attribute__((return_typestate(state)))
-#else
-#    define CONSUMABLE(initial_state)
-#    define CALLABLE_WHEN(...)
-#    define SET_TYPESTATE(state)
-#    define RETURN_TYPESTATE(state)
-#endif
-
 #ifndef __serenity__
 #ifndef __serenity__
 #    define PAGE_SIZE sysconf(_SC_PAGESIZE)
 #    define PAGE_SIZE sysconf(_SC_PAGESIZE)
 
 

+ 1 - 3
CMakeLists.txt

@@ -101,9 +101,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -Wno-sized-deallocation -fno-sized-d
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG -DSANITIZE_PTRS")
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG -DSANITIZE_PTRS")
 add_link_options(--sysroot ${CMAKE_BINARY_DIR}/Root)
 add_link_options(--sysroot ${CMAKE_BINARY_DIR}/Root)
 
 
-if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
-    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wconsumed")
-elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
+if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-expansion-to-defined")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-expansion-to-defined")
 endif()
 endif()