#include "partition_alloc/pointers/raw_ref.h"
#include <functional>
#include <type_traits>
#include "base/test/gtest_util.h"
#include "partition_alloc/buildflags.h"
#include "partition_alloc/pointers/raw_ptr.h"
#include "partition_alloc/pointers/raw_ptr_counting_impl_for_test.h"
#include "partition_alloc/pointers/raw_ptr_test_support.h"
#include "testing/gtest/include/gtest/gtest.h"
#if PA_BUILDFLAG(USE_ASAN_BACKUP_REF_PTR)
#include "base/debug/asan_service.h"
#include "base/memory/raw_ptr_asan_service.h"
#endif
namespace {
class BaseClass { … };
class SubClass : public BaseClass { … };
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
static_assert …;
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201907L
static_assert …;
#endif
struct StructWithoutTypeBasedTraits { … };
struct BaseWithTypeBasedTraits { … };
struct DerivedWithTypeBasedTraits : BaseWithTypeBasedTraits { … };
}
namespace base::raw_ptr_traits {
kTypeTraits;
}
static_assert …;
static_assert …;
static_assert …;
namespace {
TEST(RawRef, Construct) { … }
TEST(RawRef, CopyConstruct) { … }
TEST(RawRef, MoveConstruct) { … }
TEST(RawRef, CopyAssign) { … }
TEST(RawRef, CopyReassignAfterMove) { … }
TEST(RawRef, MoveAssign) { … }
TEST(RawRef, MoveReassignAfterMove) { … }
TEST(RawRef, CopyConstructUpCast) { … }
TEST(RawRef, MoveConstructUpCast) { … }
TEST(RawRef, FromPtr) { … }
TEST(RawRef, CopyAssignUpCast) { … }
TEST(RawRef, MoveAssignUpCast) { … }
TEST(RawRef, Deref) { … }
TEST(RawRef, Arrow) { … }
TEST(RawRef, Swap) { … }
TEST(RawRef, Equals) { … }
TEST(RawRef, NotEquals) { … }
TEST(RawRef, LessThan) { … }
TEST(RawRef, GreaterThan) { … }
TEST(RawRef, LessThanOrEqual) { … }
TEST(RawRef, GreaterThanOrEqual) { … }
#if PA_BUILDFLAG(ENABLE_BACKUP_REF_PTR_SUPPORT) || \
PA_BUILDFLAG(USE_ASAN_BACKUP_REF_PTR) || PA_BUILDFLAG(DCHECKS_ARE_ON)
TEST(RawRefDeathTest, CopyConstructAfterMove) { … }
TEST(RawRefDeathTest, MoveConstructAfterMove) { … }
TEST(RawRefDeathTest, CopyAssignAfterMove) { … }
TEST(RawRefDeathTest, MoveAssignAfterMove) { … }
TEST(RawRefDeathTest, CopyConstructAfterMoveUpCast) { … }
TEST(RawRefDeathTest, MoveConstructAfterMoveUpCast) { … }
TEST(RawRefDeathTest, FromPtrWithNullptr) { … }
TEST(RawRefDeathTest, CopyAssignAfterMoveUpCast) { … }
TEST(RawRefDeathTest, MoveAssignAfterMoveUpCast) { … }
TEST(RawRefDeathTest, DerefAfterMove) { … }
TEST(RawRefDeathTest, ArrowAfterMove) { … }
TEST(RawRefDeathTest, SwapAfterMove) { … }
TEST(RawRefDeathTest, EqualsAfterMove) { … }
TEST(RawRefDeathTest, NotEqualsAfterMove) { … }
TEST(RawRefDeathTest, LessThanAfterMove) { … }
TEST(RawRefDeathTest, GreaterThanAfterMove) { … }
TEST(RawRefDeathTest, LessThanOrEqualAfterMove) { … }
TEST(RawRefDeathTest, GreaterThanOrEqualAfterMove) { … }
#endif
TEST(RawRef, CTAD) { … }
TEST(RawRefPtr, CTADWithConst) { … }
RawPtrCountingImpl;
CountingRawRef;
static_assert …;
CountingRawRefMayDangle;
static_assert …;
TEST(RawRef, StdLess) { … }
TEST(RawRef, OperatorsUseGetForComparison) { … }
TEST(RawRef, CrossKindConversion) { … }
TEST(RawRef, CrossKindAssignment) { … }
#if PA_BUILDFLAG(USE_ASAN_BACKUP_REF_PTR)
TEST(AsanBackupRefPtrImpl, RawRefGet) {
base::debug::AsanService::GetInstance()->Initialize();
if (!base::RawPtrAsanService::GetInstance().IsEnabled()) {
base::RawPtrAsanService::GetInstance().Configure(
base::EnableDereferenceCheck(true), base::EnableExtractionCheck(true),
base::EnableInstantiationCheck(true));
} else {
ASSERT_TRUE(
base::RawPtrAsanService::GetInstance().is_dereference_check_enabled());
ASSERT_TRUE(
base::RawPtrAsanService::GetInstance().is_extraction_check_enabled());
ASSERT_TRUE(base::RawPtrAsanService::GetInstance()
.is_instantiation_check_enabled());
}
auto ptr = ::std::make_unique<int>();
raw_ref<int> safe_ref(*ptr);
ptr.reset();
[[maybe_unused]] volatile int& ref = safe_ref.get();
}
TEST(AsanBackupRefPtrImpl, RawRefOperatorStar) {
base::debug::AsanService::GetInstance()->Initialize();
if (!base::RawPtrAsanService::GetInstance().IsEnabled()) {
base::RawPtrAsanService::GetInstance().Configure(
base::EnableDereferenceCheck(true), base::EnableExtractionCheck(true),
base::EnableInstantiationCheck(true));
} else {
ASSERT_TRUE(
base::RawPtrAsanService::GetInstance().is_dereference_check_enabled());
ASSERT_TRUE(
base::RawPtrAsanService::GetInstance().is_extraction_check_enabled());
ASSERT_TRUE(base::RawPtrAsanService::GetInstance()
.is_instantiation_check_enabled());
}
auto ptr = ::std::make_unique<int>();
raw_ref<int> safe_ref(*ptr);
ptr.reset();
[[maybe_unused]] volatile int& ref = *safe_ref;
}
#endif
}