Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 05ef8e5

Browse files
committed
Reapply "ADT: Tidy up ilist_traits static asserts, NFC"
This spiritually reapplies r279012 (reverted in r279052) without the r278974 parts. The differences: - Only the HasGetNext trait exists here, so I've only cleaned up (and tested) it. I still added HasObsoleteCustomization since I know this will be expanding when r278974 is reapplied. - I changed the unit tests to use static_assert to catch problems earlier in the build. - I added negative tests for the type traits. Original commit message follows. ---- 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279312 91177308-0d34-0410-b5e6-96231b3b80d8 (cherry picked from commit 118c004)
1 parent 31f80a2 commit 05ef8e5

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

include/llvm/ADT/ilist.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,15 @@ template <class TraitsT, class NodeT> struct HasGetNext {
8585
template <size_t N> struct SFINAE {};
8686

8787
template <class U>
88-
static Yes &hasGetNext(
89-
SFINAE<sizeof(static_cast<NodeT *>(make<U>().getNext(&make<NodeT>())))>
90-
* = 0);
91-
template <class U> static No &hasGetNext(...);
88+
static Yes &test(U *I, decltype(I->getNext(&make<NodeT>())) * = 0);
89+
template <class> static No &test(...);
9290

93-
static const bool value = sizeof(hasGetNext<TraitsT>(nullptr)) == sizeof(Yes);
91+
public:
92+
static const bool value = sizeof(test<TraitsT>(nullptr)) == sizeof(Yes);
93+
};
94+
95+
template <class TraitsT, class NodeT> struct HasObsoleteCustomization {
96+
static const bool value = HasGetNext<TraitsT, NodeT>::value;
9497
};
9598

9699
} // end namespace ilist_detail
@@ -378,12 +381,11 @@ template<typename NodeTy> struct simplify_type<const ilist_iterator<NodeTy> > {
378381
///
379382
template <typename NodeTy, typename Traits = ilist_traits<NodeTy>>
380383
class iplist : public Traits, ilist_node_access {
381-
#if !defined(_MSC_VER)
382-
// FIXME: This fails in MSVC, but it's worth keeping around to help
383-
// non-Windows users root out bugs in their ilist_traits.
384-
static_assert(!ilist_detail::HasGetNext<Traits, NodeTy>::value,
385-
"ilist next and prev links are not customizable!");
386-
#endif
384+
// TODO: Drop this assertion and the transitive type traits anytime after
385+
// v4.0 is branched (i.e,. keep them for one release to help out-of-tree code
386+
// update).
387+
static_assert(!ilist_detail::HasObsoleteCustomization<Traits, NodeTy>::value,
388+
"ilist customization points have changed!");
387389

388390
mutable NodeTy *Head;
389391

unittests/ADT/ilistTest.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,25 @@ TEST(ilistTest, UnsafeClear) {
9696
EXPECT_EQ(6, List.back().Value);
9797
}
9898

99+
struct Empty {};
100+
TEST(ilistTest, HasObsoleteCustomizationTrait) {
101+
// Negative test for HasObsoleteCustomization.
102+
static_assert(!ilist_detail::HasObsoleteCustomization<Empty, Node>::value,
103+
"Empty has no customizations");
99104
}
105+
106+
struct GetNext {
107+
Node *getNext(Node *);
108+
};
109+
TEST(ilistTest, HasGetNextTrait) {
110+
static_assert(ilist_detail::HasGetNext<GetNext, Node>::value,
111+
"GetNext has a getNext(Node*)");
112+
static_assert(ilist_detail::HasObsoleteCustomization<GetNext, Node>::value,
113+
"Empty should be obsolete because of getNext()");
114+
115+
// Negative test for HasGetNext.
116+
static_assert(!ilist_detail::HasGetNext<Empty, Node>::value,
117+
"Empty does not have a getNext(Node*)");
118+
}
119+
120+
} // end namespace

0 commit comments

Comments
 (0)