diff --git a/AK/NonnullOwnPtr.h b/AK/NonnullOwnPtr.h index 5b9dc53e496..622290578a2 100644 --- a/AK/NonnullOwnPtr.h +++ b/AK/NonnullOwnPtr.h @@ -42,25 +42,22 @@ template class WeakPtr; template -class CONSUMABLE(unconsumed) NonnullOwnPtr { +class NonnullOwnPtr { public: typedef T ElementType; enum AdoptTag { Adopt }; - RETURN_TYPESTATE(unconsumed) NonnullOwnPtr(AdoptTag, T& ptr) : m_ptr(&ptr) { } - RETURN_TYPESTATE(unconsumed) NonnullOwnPtr(NonnullOwnPtr&& other) : m_ptr(other.leak_ptr()) { ASSERT(m_ptr); } template - RETURN_TYPESTATE(unconsumed) NonnullOwnPtr(NonnullOwnPtr&& other) : m_ptr(other.leak_ptr()) { @@ -97,7 +94,6 @@ public: template NonnullOwnPtr& operator=(const WeakPtr&) = delete; - RETURN_TYPESTATE(unconsumed) NonnullOwnPtr& operator=(NonnullOwnPtr&& other) { NonnullOwnPtr ptr(move(other)); @@ -106,7 +102,6 @@ public: } template - RETURN_TYPESTATE(unconsumed) NonnullOwnPtr& operator=(NonnullOwnPtr&& other) { NonnullOwnPtr ptr(move(other)); @@ -114,31 +109,21 @@ public: return *this; } - CALLABLE_WHEN(unconsumed) - SET_TYPESTATE(consumed) T* leak_ptr() { return exchange(m_ptr, nullptr); } - CALLABLE_WHEN(unconsumed) T* ptr() { return m_ptr; } - CALLABLE_WHEN(unconsumed) const T* ptr() const { return m_ptr; } - CALLABLE_WHEN(unconsumed) T* operator->() { return m_ptr; } - CALLABLE_WHEN(unconsumed) const T* operator->() const { return m_ptr; } - CALLABLE_WHEN(unconsumed) T& operator*() { return *m_ptr; } - CALLABLE_WHEN(unconsumed) const T& operator*() const { return *m_ptr; } - CALLABLE_WHEN(unconsumed) operator const T*() const { return m_ptr; } - CALLABLE_WHEN(unconsumed) operator T*() { return m_ptr; } operator bool() const = delete; diff --git a/AK/NonnullRefPtr.h b/AK/NonnullRefPtr.h index 3710f075347..30a33f66d40 100644 --- a/AK/NonnullRefPtr.h +++ b/AK/NonnullRefPtr.h @@ -53,49 +53,42 @@ inline void unref_if_not_null(T* ptr) } template -class CONSUMABLE(unconsumed) NonnullRefPtr { +class NonnullRefPtr { public: typedef T ElementType; enum AdoptTag { Adopt }; - RETURN_TYPESTATE(unconsumed) NonnullRefPtr(const T& object) : m_ptr(const_cast(&object)) { m_ptr->ref(); } template - RETURN_TYPESTATE(unconsumed) NonnullRefPtr(const U& object) : m_ptr(&const_cast(object)) { m_ptr->ref(); } - RETURN_TYPESTATE(unconsumed) NonnullRefPtr(AdoptTag, T& object) : m_ptr(&object) { } - RETURN_TYPESTATE(unconsumed) NonnullRefPtr(NonnullRefPtr&& other) : m_ptr(&other.leak_ref()) { } template - RETURN_TYPESTATE(unconsumed) NonnullRefPtr(NonnullRefPtr&& other) : m_ptr(&other.leak_ref()) { } - RETURN_TYPESTATE(unconsumed) NonnullRefPtr(const NonnullRefPtr& other) : m_ptr(const_cast(other.ptr())) { m_ptr->ref(); } template - RETURN_TYPESTATE(unconsumed) NonnullRefPtr(const NonnullRefPtr& other) : m_ptr(const_cast(other.ptr())) { @@ -162,73 +155,61 @@ public: return *this; } - [[nodiscard]] CALLABLE_WHEN(unconsumed) - SET_TYPESTATE(consumed) - T& leak_ref() + [[nodiscard]] T& leak_ref() { ASSERT(m_ptr); return *exchange(m_ptr, nullptr); } - CALLABLE_WHEN("unconsumed", "unknown") T* ptr() { ASSERT(m_ptr); return m_ptr; } - CALLABLE_WHEN("unconsumed", "unknown") const T* ptr() const { ASSERT(m_ptr); return m_ptr; } - CALLABLE_WHEN(unconsumed) T* operator->() { ASSERT(m_ptr); return m_ptr; } - CALLABLE_WHEN(unconsumed) const T* operator->() const { ASSERT(m_ptr); return m_ptr; } - CALLABLE_WHEN(unconsumed) T& operator*() { ASSERT(m_ptr); return *m_ptr; } - CALLABLE_WHEN(unconsumed) const T& operator*() const { ASSERT(m_ptr); return *m_ptr; } - CALLABLE_WHEN(unconsumed) operator T*() { ASSERT(m_ptr); return m_ptr; } - CALLABLE_WHEN(unconsumed) operator const T*() const { ASSERT(m_ptr); return m_ptr; } - CALLABLE_WHEN(unconsumed) operator T&() { ASSERT(m_ptr); return *m_ptr; } - CALLABLE_WHEN(unconsumed) operator const T&() const { ASSERT(m_ptr); diff --git a/AK/Optional.h b/AK/Optional.h index 37b4647e6b9..db9ee7b014e 100644 --- a/AK/Optional.h +++ b/AK/Optional.h @@ -34,12 +34,10 @@ namespace AK { template -class CONSUMABLE(unknown) alignas(T) Optional { +class alignas(T) Optional { public: - RETURN_TYPESTATE(unknown) Optional() {} - RETURN_TYPESTATE(unknown) Optional(const T& value) : m_has_value(true) { @@ -47,21 +45,18 @@ public: } template - RETURN_TYPESTATE(unknown) Optional(const U& value) : m_has_value(true) { new (&m_storage) T(value); } - RETURN_TYPESTATE(unknown) Optional(T&& value) : m_has_value(true) { new (&m_storage) T(move(value)); } - RETURN_TYPESTATE(unknown) Optional(Optional&& other) : m_has_value(other.m_has_value) { @@ -71,7 +66,6 @@ public: } } - RETURN_TYPESTATE(unknown) Optional(const Optional& other) : m_has_value(other.m_has_value) { @@ -80,7 +74,6 @@ public: } } - RETURN_TYPESTATE(unknown) Optional& operator=(const Optional& other) { if (this != &other) { @@ -93,7 +86,6 @@ public: return *this; } - RETURN_TYPESTATE(unknown) Optional& operator=(Optional&& other) { if (this != &other) { @@ -118,23 +110,19 @@ public: } } - SET_TYPESTATE(consumed) ALWAYS_INLINE bool has_value() const { return m_has_value; } - CALLABLE_WHEN(consumed) ALWAYS_INLINE T& value() { ASSERT(m_has_value); return *reinterpret_cast(&m_storage); } - CALLABLE_WHEN(consumed) ALWAYS_INLINE const T& value() const { return value_without_consume_state(); } - CALLABLE_WHEN(consumed) T release_value() { ASSERT(m_has_value); diff --git a/AK/Platform.h b/AK/Platform.h index df72a1cd09e..b745e6a780f 100644 --- a/AK/Platform.h +++ b/AK/Platform.h @@ -51,19 +51,6 @@ #endif #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__ # define PAGE_SIZE sysconf(_SC_PAGESIZE) diff --git a/CMakeLists.txt b/CMakeLists.txt index 34b6550a550..541b3dcf979 100644 --- a/CMakeLists.txt +++ b/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") 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") endif()