diff options
author | Stephen Hines <srhines@google.com> | 2013-08-07 15:07:10 -0700 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2013-08-07 15:07:10 -0700 |
commit | fab2daa4a1127ecb217abe2b07c1769122b6fee1 (patch) | |
tree | 268ebfd1963fd98ba412e76819afdf95a7d4267b /unittests/Support/Casting.cpp | |
parent | 8197ac1c1a0a91baa70c4dea8cb488f254ef974c (diff) | |
parent | 10251753b6897adcd22cc981c0cc42f348c109de (diff) | |
download | external_llvm-fab2daa4a1127ecb217abe2b07c1769122b6fee1.zip external_llvm-fab2daa4a1127ecb217abe2b07c1769122b6fee1.tar.gz external_llvm-fab2daa4a1127ecb217abe2b07c1769122b6fee1.tar.bz2 |
Merge commit '10251753b6897adcd22cc981c0cc42f348c109de' into merge-20130807
Conflicts:
lib/Archive/ArchiveReader.cpp
lib/Support/Unix/PathV2.inc
Change-Id: I29d8c1e321a4a380b6013f00bac6a8e4b593cc4e
Diffstat (limited to 'unittests/Support/Casting.cpp')
-rw-r--r-- | unittests/Support/Casting.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/unittests/Support/Casting.cpp b/unittests/Support/Casting.cpp index 01583e4..362abee 100644 --- a/unittests/Support/Casting.cpp +++ b/unittests/Support/Casting.cpp @@ -10,10 +10,15 @@ #include "llvm/Support/Casting.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/IR/User.h" #include "gtest/gtest.h" #include <cstdlib> namespace llvm { +// Used to test illegal cast. If a cast doesn't match any of the "real" ones, +// it will match this one. +struct IllegalCast; +template <typename T> IllegalCast *cast(...) { return 0; } // set up two example classes // with conversion facility @@ -60,10 +65,25 @@ foo *bar::naz() { bar *fub(); + +template <> struct simplify_type<foo> { + typedef int SimpleType; + static SimpleType getSimplifiedValue(foo &Val) { return 0; } +}; + } // End llvm namespace using namespace llvm; + +// Test the peculiar behavior of Use in simplify_type. +int Check1[is_same<simplify_type<Use>::SimpleType, Value *>::value ? 1 : -1]; +int Check2[is_same<simplify_type<Use *>::SimpleType, Value *>::value ? 1 : -1]; + +// Test that a regular class behaves as expected. +int Check3[is_same<simplify_type<foo>::SimpleType, int>::value ? 1 : -1]; +int Check4[is_same<simplify_type<foo *>::SimpleType, foo *>::value ? 1 : -1]; + namespace { const foo *null_foo = NULL; @@ -203,3 +223,8 @@ TEST(CastingTest, InferredUpcastTakesPrecedence) { } // end namespace inferred_upcasting } // end anonymous namespace +// Test that we reject casts of temporaries (and so the illegal cast gets used). +namespace TemporaryCast { +struct pod {}; +IllegalCast *testIllegalCast() { return cast<foo>(pod()); } +} |