forked from OSchip/llvm-project
Revert "[LLVM][Casting.h] Add trivial self-cast"
This reverts commit 0809f63826
. The patch appears not to have included corresponding isa<Ty> support.
This was revealed when reintroducing the required isa<Ty> asserts in cast<Ty>. See https://discourse.llvm.org/t/cast-x-is-broken-implications-and-proposal-to-address/63033 for context.
Here's the template instantiation error:
In file included from /home/preames/llvm-repo/llvm-project/llvm/unittests/Support/Casting.cpp:9:
/home/preames/llvm-repo/llvm-project/llvm/include/llvm/Support/Casting.h: In instantiation of ‘static bool llvm::isa_impl<To, From, Enabler>::doit(const From&) [with To = llvm::bar*; From = llvm::bar; Enabler = void]’:
/home/preames/llvm-repo/llvm-project/llvm/include/llvm/Support/Casting.h:110:36: required from ‘static bool llvm::isa_impl_cl<To, const From*>::doit(const From*) [with To = llvm::bar*; From = llvm::bar]’
/home/preames/llvm-repo/llvm-project/llvm/include/llvm/Support/Casting.h:137:41: required from ‘static bool llvm::isa_impl_wrap<To, FromTy, FromTy>::doit(const FromTy&) [with To = llvm::bar*; FromTy = const llvm::bar*]’
/home/preames/llvm-repo/llvm-project/llvm/include/llvm/Support/Casting.h:129:13: required from ‘static bool llvm::isa_impl_wrap<To, From, SimpleFrom>::doit(const From&) [with To = llvm::bar*; From = const llvm::bar* const; SimpleFrom = const llvm::bar*]’
/home/preames/llvm-repo/llvm-project/llvm/include/llvm/Support/Casting.h:263:62: required from ‘static bool llvm::CastIsPossible<To, From, Enable>::isPossible(const From&) [with To = llvm::bar*; From = const llvm::bar*; Enable = void]’
/home/preames/llvm-repo/llvm-project/llvm/include/llvm/Support/Casting.h:517:38: required from ‘static bool llvm::CastInfo<To, From, typename std::enable_if<(! llvm::is_simple_type<From>::value), void>::type>::isPossible(From&) [with To = llvm::bar*; From = llvm::bar* const]’
/home/preames/llvm-repo/llvm-project/llvm/include/llvm/Support/Casting.h:556:46: required from ‘bool llvm::isa(const From&) [with To = llvm::bar*; From = llvm::bar*]’
/home/preames/llvm-repo/llvm-project/llvm/include/llvm/Support/Casting.h:585:3: required from ‘decltype(auto) llvm::cast(From*) [with To = llvm::bar*; From = llvm::bar]’
/home/preames/llvm-repo/llvm-project/llvm/unittests/Support/Casting.cpp:181:27: required from here
/home/preames/llvm-repo/llvm-project/llvm/include/llvm/Support/Casting.h:64:64: error: ‘classof’ is not a member of ‘llvm::bar*’
64 | static inline bool doit(const From &Val) { return To::classof(&Val); }
This commit is contained in:
parent
dd2a6d78ee
commit
781de11f42
|
@ -192,12 +192,6 @@ template <class To, class From> struct cast_retty {
|
||||||
To, From, typename simplify_type<From>::SimpleType>::ret_type;
|
To, From, typename simplify_type<From>::SimpleType>::ret_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T> struct cast_retty<T, T> {
|
|
||||||
// Casting T to itself, but have to use a ref if so we don't get a copy if
|
|
||||||
// it's not a pointer.
|
|
||||||
using ret_type = std::conditional_t<std::is_pointer<T>::value, T, T &>;
|
|
||||||
};
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// cast_convert_val
|
// cast_convert_val
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -282,8 +276,7 @@ struct CastIsPossible<To, Optional<From>> {
|
||||||
/// always be possible.
|
/// always be possible.
|
||||||
template <typename To, typename From>
|
template <typename To, typename From>
|
||||||
struct CastIsPossible<To, From,
|
struct CastIsPossible<To, From,
|
||||||
std::enable_if_t<std::is_same<To, From>::value ||
|
std::enable_if_t<std::is_base_of<To, From>::value>> {
|
||||||
std::is_base_of<To, From>::value>> {
|
|
||||||
static inline bool isPossible(const From &f) { return true; }
|
static inline bool isPossible(const From &f) { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -144,7 +144,6 @@ extern const bar *B2;
|
||||||
// test various configurations of const
|
// test various configurations of const
|
||||||
const bar &B3 = B1;
|
const bar &B3 = B1;
|
||||||
const bar *const B4 = B2;
|
const bar *const B4 = B2;
|
||||||
bar *B5 = &B;
|
|
||||||
|
|
||||||
TEST(CastingTest, isa) {
|
TEST(CastingTest, isa) {
|
||||||
EXPECT_TRUE(isa<foo>(B1));
|
EXPECT_TRUE(isa<foo>(B1));
|
||||||
|
@ -176,17 +175,6 @@ TEST(CastingTest, cast) {
|
||||||
foo *F8 = B1.baz();
|
foo *F8 = B1.baz();
|
||||||
EXPECT_NE(F8, null_foo);
|
EXPECT_NE(F8, null_foo);
|
||||||
|
|
||||||
// Ensure cast-to-self works (with the type in the template verbatim
|
|
||||||
// equivalent to the type in the input).
|
|
||||||
auto B9 = cast<bar *>(B5);
|
|
||||||
static_assert(std::is_same<bar *, decltype(B9)>::value,
|
|
||||||
"Inccorrect return type!");
|
|
||||||
EXPECT_EQ(B9, B5);
|
|
||||||
auto B10 = cast<const bar *>(B2);
|
|
||||||
static_assert(std::is_same<const bar *, decltype(B10)>::value,
|
|
||||||
"Inccorrect return type!");
|
|
||||||
EXPECT_EQ(B10, B2);
|
|
||||||
|
|
||||||
std::unique_ptr<const bar> BP(B2);
|
std::unique_ptr<const bar> BP(B2);
|
||||||
auto FP = cast<foo>(std::move(BP));
|
auto FP = cast<foo>(std::move(BP));
|
||||||
static_assert(std::is_same<std::unique_ptr<const foo>, decltype(FP)>::value,
|
static_assert(std::is_same<std::unique_ptr<const foo>, decltype(FP)>::value,
|
||||||
|
@ -224,17 +212,6 @@ TEST(CastingTest, dyn_cast) {
|
||||||
// EXPECT_EQ(F4, null_foo);
|
// EXPECT_EQ(F4, null_foo);
|
||||||
foo *F5 = B1.daz();
|
foo *F5 = B1.daz();
|
||||||
EXPECT_NE(F5, null_foo);
|
EXPECT_NE(F5, null_foo);
|
||||||
|
|
||||||
// Ensure cast-to-self works (with the type in the template verbatim
|
|
||||||
// equivalent to the type in the input).
|
|
||||||
auto B9 = dyn_cast<bar *>(B5);
|
|
||||||
static_assert(std::is_same<bar *, decltype(B9)>::value,
|
|
||||||
"Inccorrect return type!");
|
|
||||||
EXPECT_EQ(B9, B5);
|
|
||||||
auto B10 = dyn_cast<const bar *>(B2);
|
|
||||||
static_assert(std::is_same<const bar *, decltype(B10)>::value,
|
|
||||||
"Inccorrect return type!");
|
|
||||||
EXPECT_EQ(B10, B2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// All these tests forward to dyn_cast_if_present, so they also provde an
|
// All these tests forward to dyn_cast_if_present, so they also provde an
|
||||||
|
|
Loading…
Reference in New Issue