summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-08-17 23:47:56 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-08-17 23:47:56 +0000
commit56ee4f1fb786168f05c41cfeb939ba04362b2f16 (patch)
treee8bc2724ca46f1cf3ea3dc612b4c11aca4adcb6d
parenta8a638292ced193f5e00dd1e087b46790cf540cb (diff)
downloadbcm5719-llvm-56ee4f1fb786168f05c41cfeb939ba04362b2f16.tar.gz
bcm5719-llvm-56ee4f1fb786168f05c41cfeb939ba04362b2f16.zip
ADT: Tidy up ilist_traits static asserts, NFC
Change the ilist traits to use decltype instead of sizeof, and add HasObsoleteCustomization so that additions to this list don't need to be added in two places. I suspect this will now work with MSVC, since the trait tested in r278991 seems to work. If for some reason it continues to fail on Windows I'll follow up by adding back the #ifndef _MSC_VER. llvm-svn: 279012
-rw-r--r--llvm/include/llvm/ADT/ilist.h35
-rw-r--r--llvm/unittests/ADT/ilistTest.cpp17
2 files changed, 33 insertions, 19 deletions
diff --git a/llvm/include/llvm/ADT/ilist.h b/llvm/include/llvm/ADT/ilist.h
index 10ff088dcd6..c77730c99a3 100644
--- a/llvm/include/llvm/ADT/ilist.h
+++ b/llvm/include/llvm/ADT/ilist.h
@@ -83,34 +83,37 @@ template <class T> T &make();
/// Type trait to check for a traits class that has a getNext member (as a
/// canary for any of the ilist_nextprev_traits API).
-template <class TraitsT, class NodeT> struct HasGetNext {
+template <class TraitsT, class NodeT> class HasGetNext {
typedef char Yes[1];
typedef char No[2];
template <size_t N> struct SFINAE {};
template <class U>
- static Yes &hasGetNext(
- SFINAE<sizeof(static_cast<NodeT *>(make<U>().getNext(&make<NodeT>())))>
- * = 0);
- template <class U> static No &hasGetNext(...);
+ static Yes &test(U *I, decltype(I->getNext(&make<NodeT>())) * = 0);
+ template <class> static No &test(...);
- static const bool value = sizeof(hasGetNext<TraitsT>(nullptr)) == sizeof(Yes);
+public:
+ static const bool value = sizeof(test<TraitsT>(nullptr)) == sizeof(Yes);
};
/// Type trait to check for a traits class that has a createSentinel member (as
/// a canary for any of the ilist_sentinel_traits API).
-template <class TraitsT> struct HasCreateSentinel {
+template <class TraitsT> class HasCreateSentinel {
typedef char Yes[1];
typedef char No[2];
template <size_t N> struct SFINAE {};
template <class U>
- static Yes &
- hasCreateSentinel(SFINAE<sizeof(make<U>().createSentinel())> * = 0);
- template <class U> static No &hasCreateSentinel(...);
+ static Yes &test(U *I, decltype(I->createSentinel()) * = 0);
+ template <class U> static No &test(...);
+
+public:
+ static const bool value = sizeof(test<TraitsT>(nullptr)) == sizeof(Yes);
+};
+template <class TraitsT, class NodeT> struct HasObsoleteCustomization {
static const bool value =
- sizeof(hasCreateSentinel<TraitsT>(nullptr)) == sizeof(Yes);
+ HasGetNext<TraitsT, NodeT>::value || HasCreateSentinel<TraitsT>::value;
};
} // end namespace ilist_detail
@@ -287,14 +290,8 @@ template <typename NodeTy, typename Traits = ilist_traits<NodeTy>>
class iplist : public Traits, ilist_node_access {
// TODO: Drop these assertions anytime after 4.0 is branched (keep them for
// one release to help out-of-tree code update).
-#if !defined(_MSC_VER)
- // FIXME: This fails in MSVC, but it's worth keeping around to help
- // non-Windows users root out bugs in their ilist_traits.
- static_assert(!ilist_detail::HasGetNext<Traits, NodeTy>::value,
- "ilist next and prev links are not customizable!");
- static_assert(!ilist_detail::HasCreateSentinel<Traits>::value,
- "ilist sentinel is not customizable!");
-#endif
+ static_assert(!ilist_detail::HasObsoleteCustomization<Traits, NodeTy>::value,
+ "ilist customization points have changed!");
ilist_sentinel<NodeTy> Sentinel;
diff --git a/llvm/unittests/ADT/ilistTest.cpp b/llvm/unittests/ADT/ilistTest.cpp
index a8ea63ed464..57cdd584ec1 100644
--- a/llvm/unittests/ADT/ilistTest.cpp
+++ b/llvm/unittests/ADT/ilistTest.cpp
@@ -190,4 +190,21 @@ TEST(ilistTest, privateNode) {
L2.remove(&N);
}
+struct GetNext {
+ Node *getNext(Node *);
+};
+TEST(ilistTest, HasGetNextTrait) {
+ EXPECT_TRUE((ilist_detail::HasGetNext<GetNext, Node>::value));
+ EXPECT_TRUE((ilist_detail::HasObsoleteCustomization<GetNext, Node>::value));
+}
+
+struct CreateSentinel {
+ Node *createSentinel();
+};
+TEST(ilistTest, HasCreateSentinel) {
+ EXPECT_TRUE((ilist_detail::HasCreateSentinel<CreateSentinel>::value));
+ EXPECT_TRUE(
+ (ilist_detail::HasObsoleteCustomization<CreateSentinel, Node>::value));
+}
+
} // end namespace
OpenPOWER on IntegriCloud