From e8950977a5cf929ab15b6c5f7265a029500d9a7d Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Tue, 20 Jul 2010 17:06:28 +0000 Subject: [PATCH] migrate essentially everything from under #ifdef DEBUG_CAST_OPERATORS into this file git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108864 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/Support/Casting.cpp | 62 +++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 7 deletions(-) diff --git a/unittests/Support/Casting.cpp b/unittests/Support/Casting.cpp index 22badb47c7c..4e689ec1d2c 100644 --- a/unittests/Support/Casting.cpp +++ b/unittests/Support/Casting.cpp @@ -9,12 +9,47 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Support/Debug.h" -#define DEBUG_CAST_OPERATORS +//#define DEBUG_CAST_OPERATORS #include "llvm/Support/Casting.h" #include "gtest/gtest.h" #include + +namespace llvm { + +// set up two example classes +// with conversion facility +// +struct bar { + bar() {} + //struct foo *baz(); +private: + bar(const bar &); +}; +struct foo { + void ext() const; + /* static bool classof(const bar *X) { + cerr << "Classof: " << X << "\n"; + return true; + }*/ +}; + +template <> struct isa_impl { + static inline bool doit(const bar &Val) { + dbgs() << "Classof: " << &Val << "\n"; + return true; + } +}; + +/*foo *bar::baz() { + return cast(this); +}*/ + + +bar *fub(); +} // End llvm namespace + using namespace llvm; namespace { @@ -41,12 +76,15 @@ TEST(CastingTest, cast) { EXPECT_NE(F3, null_foo); const foo *F4 = cast(B2); EXPECT_NE(F4, null_foo); - const foo &F8 = cast(B3); - EXPECT_NE(&F8, null_foo); - const foo *F9 = cast(B4); - EXPECT_NE(F9, null_foo); - foo *F10 = cast(fub()); - EXPECT_EQ(F10, null_foo); + const foo &F5 = cast(B3); + EXPECT_NE(&F5, null_foo); + const foo *F6 = cast(B4); + EXPECT_NE(F6, null_foo); + foo *F7 = cast(fub()); + EXPECT_EQ(F7, null_foo); + +/* foo *F8 = B1.baz(); + EXPECT_NE(F8, null_foo);*/ } TEST(CastingTest, cast_or_null) { @@ -60,7 +98,17 @@ TEST(CastingTest, cast_or_null) { EXPECT_EQ(F14, null_foo); } +// These lines are errors... +//foo *F20 = cast(B2); // Yields const foo* +//foo &F21 = cast(B3); // Yields const foo& +//foo *F22 = cast(B4); // Yields const foo* +//foo &F23 = cast_or_null(B1); +//const foo &F24 = cast_or_null(B3); + + bar B; bar &B1 = B; const bar *B2 = &B; } // anonymous namespace + +bar *llvm::fub() { return 0; }