xref: /llvm-project/llvm/unittests/ADT/IListNodeTest.cpp (revision c6ed8289b7c948464855841632f6b6783da1b65a)
1 //===- unittests/ADT/IListNodeTest.cpp - ilist_node unit tests ------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/ADT/ilist_node.h"
10 #include "gtest/gtest.h"
11 #include <type_traits>
12 
13 using namespace llvm;
14 using namespace llvm::ilist_detail;
15 
16 namespace {
17 
18 struct Node;
19 
20 struct TagA {};
21 struct TagB {};
22 struct ParentA {};
23 struct ParentB {};
24 
TEST(IListNodeTest,Options)25 TEST(IListNodeTest, Options) {
26   static_assert(
27       std::is_same_v<compute_node_options<Node>::type,
28                      compute_node_options<Node, ilist_tag<void>>::type>,
29       "default tag is void");
30   static_assert(
31       !std::is_same_v<compute_node_options<Node, ilist_tag<TagA>>::type,
32                       compute_node_options<Node, ilist_tag<void>>::type>,
33       "default tag is void, different from TagA");
34   static_assert(
35       !std::is_same_v<compute_node_options<Node, ilist_tag<TagA>>::type,
36                       compute_node_options<Node, ilist_tag<TagB>>::type>,
37       "TagA is not TagB");
38   static_assert(
39       std::is_same_v<
40           compute_node_options<Node, ilist_sentinel_tracking<false>>::type,
41           compute_node_options<Node, ilist_sentinel_tracking<false>,
42                                ilist_tag<void>>::type>,
43       "default tag is void, even with sentinel tracking off");
44   static_assert(
45       std::is_same_v<
46           compute_node_options<Node, ilist_sentinel_tracking<false>>::type,
47           compute_node_options<Node, ilist_tag<void>,
48                                ilist_sentinel_tracking<false>>::type>,
49       "order shouldn't matter");
50   static_assert(
51       std::is_same_v<
52           compute_node_options<Node, ilist_sentinel_tracking<true>>::type,
53           compute_node_options<Node, ilist_sentinel_tracking<true>,
54                                ilist_tag<void>>::type>,
55       "default tag is void, even with sentinel tracking on");
56   static_assert(
57       std::is_same_v<
58           compute_node_options<Node, ilist_sentinel_tracking<true>>::type,
59           compute_node_options<Node, ilist_tag<void>,
60                                ilist_sentinel_tracking<true>>::type>,
61       "order shouldn't matter");
62   static_assert(
63       std::is_same_v<compute_node_options<Node, ilist_sentinel_tracking<true>,
64                                           ilist_tag<TagA>>::type,
65                      compute_node_options<Node, ilist_tag<TagA>,
66                                           ilist_sentinel_tracking<true>>::type>,
67       "order shouldn't matter with real tags");
68   static_assert(
69       std::is_same_v<compute_node_options<Node>::type,
70                      compute_node_options<Node, ilist_parent<void>>::type>,
71       "default parent is void");
72   static_assert(
73       !std::is_same_v<compute_node_options<Node, ilist_parent<ParentA>>::type,
74                       compute_node_options<Node, ilist_parent<void>>::type>,
75       "ParentA is not void");
76   static_assert(
77       !std::is_same_v<compute_node_options<Node, ilist_parent<ParentA>>::type,
78                       compute_node_options<Node, ilist_parent<ParentB>>::type>,
79       "ParentA is not ParentB");
80 }
81 
82 } // end namespace
83