From 11cb5385a9646d430cb712e4950f16b25ac44065 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Fri, 19 Aug 2016 20:17:23 +0000 Subject: [PATCH] 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. llvm-svn: 279312 --- llvm/include/llvm/ADT/ilist.h | 24 +++++++++++++----------- llvm/unittests/ADT/ilistTest.cpp | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/llvm/include/llvm/ADT/ilist.h b/llvm/include/llvm/ADT/ilist.h index 3723039..f64413d 100644 --- a/llvm/include/llvm/ADT/ilist.h +++ b/llvm/include/llvm/ADT/ilist.h @@ -85,12 +85,15 @@ template struct HasGetNext { template struct SFINAE {}; template - static Yes &hasGetNext( - SFINAE(make().getNext(&make())))> - * = 0); - template static No &hasGetNext(...); + static Yes &test(U *I, decltype(I->getNext(&make())) * = 0); + template static No &test(...); - static const bool value = sizeof(hasGetNext(nullptr)) == sizeof(Yes); +public: + static const bool value = sizeof(test(nullptr)) == sizeof(Yes); +}; + +template struct HasObsoleteCustomization { + static const bool value = HasGetNext::value; }; } // end namespace ilist_detail @@ -378,12 +381,11 @@ template struct simplify_type > { /// template > class iplist : public Traits, ilist_node_access { -#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::value, - "ilist next and prev links are not customizable!"); -#endif + // TODO: Drop this assertion and the transitive type traits anytime after + // v4.0 is branched (i.e,. keep them for one release to help out-of-tree code + // update). + static_assert(!ilist_detail::HasObsoleteCustomization::value, + "ilist customization points have changed!"); mutable NodeTy *Head; diff --git a/llvm/unittests/ADT/ilistTest.cpp b/llvm/unittests/ADT/ilistTest.cpp index b63cfd6..c2ad3d0 100644 --- a/llvm/unittests/ADT/ilistTest.cpp +++ b/llvm/unittests/ADT/ilistTest.cpp @@ -128,4 +128,25 @@ TEST(ilistTest, UnsafeClear) { EXPECT_EQ(6, List.back().Value); } +struct Empty {}; +TEST(ilistTest, HasObsoleteCustomizationTrait) { + // Negative test for HasObsoleteCustomization. + static_assert(!ilist_detail::HasObsoleteCustomization::value, + "Empty has no customizations"); } + +struct GetNext { + Node *getNext(Node *); +}; +TEST(ilistTest, HasGetNextTrait) { + static_assert(ilist_detail::HasGetNext::value, + "GetNext has a getNext(Node*)"); + static_assert(ilist_detail::HasObsoleteCustomization::value, + "Empty should be obsolete because of getNext()"); + + // Negative test for HasGetNext. + static_assert(!ilist_detail::HasGetNext::value, + "Empty does not have a getNext(Node*)"); +} + +} // end namespace -- 2.7.4