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. :/
This commit is contained in:
Andreas Kling 2020-05-16 10:51:21 +02:00
parent 16c858d9f0
commit 76bcd284f9
Notes: sideshowbarker 2024-07-19 06:37:08 +09:00
5 changed files with 5 additions and 66 deletions

View File

@ -42,25 +42,22 @@ template<typename T>
class WeakPtr;
template<typename T>
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<typename U>
RETURN_TYPESTATE(unconsumed)
NonnullOwnPtr(NonnullOwnPtr<U>&& other)
: m_ptr(other.leak_ptr())
{
@ -97,7 +94,6 @@ public:
template<typename U>
NonnullOwnPtr& operator=(const WeakPtr<U>&) = delete;
RETURN_TYPESTATE(unconsumed)
NonnullOwnPtr& operator=(NonnullOwnPtr&& other)
{
NonnullOwnPtr ptr(move(other));
@ -106,7 +102,6 @@ public:
}
template<typename U>
RETURN_TYPESTATE(unconsumed)
NonnullOwnPtr& operator=(NonnullOwnPtr<U>&& 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;

View File

@ -53,49 +53,42 @@ inline void unref_if_not_null(T* ptr)
}
template<typename T>
class CONSUMABLE(unconsumed) NonnullRefPtr {
class NonnullRefPtr {
public:
typedef T ElementType;
enum AdoptTag { Adopt };
RETURN_TYPESTATE(unconsumed)
NonnullRefPtr(const T& object)
: m_ptr(const_cast<T*>(&object))
{
m_ptr->ref();
}
template<typename U>
RETURN_TYPESTATE(unconsumed)
NonnullRefPtr(const U& object)
: m_ptr(&const_cast<U&>(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<typename U>
RETURN_TYPESTATE(unconsumed)
NonnullRefPtr(NonnullRefPtr<U>&& other)
: m_ptr(&other.leak_ref())
{
}
RETURN_TYPESTATE(unconsumed)
NonnullRefPtr(const NonnullRefPtr& other)
: m_ptr(const_cast<T*>(other.ptr()))
{
m_ptr->ref();
}
template<typename U>
RETURN_TYPESTATE(unconsumed)
NonnullRefPtr(const NonnullRefPtr<U>& other)
: m_ptr(const_cast<U*>(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);

View File

@ -34,12 +34,10 @@
namespace AK {
template<typename T>
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<typename U>
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<T*>(&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);

View File

@ -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)

View File

@ -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()