
Fixes issue reported in: https://github.com/llvm/llvm-project/pull/94224 The recent commit above added an ilist_parent<ParentTy> option, which added a parent pointer to the ilist_node_base type for the list. The const methods for returning that parent pointer however were incorrectly implemented, returning `const ParentPtrTy`, which is equivalent to `ParentTy * const` rather than `const ParentTy *`. This patch fixes this by passing around `ParentTy` in ilist's internal logic rather than `ParentPtrTy`, removing the ability to have a `void*` parent pointer but cleanly fixing this error.
83 lines
3.3 KiB
C++
83 lines
3.3 KiB
C++
//===- unittests/ADT/IListNodeTest.cpp - ilist_node unit tests ------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/ADT/ilist_node.h"
|
|
#include "gtest/gtest.h"
|
|
#include <type_traits>
|
|
|
|
using namespace llvm;
|
|
using namespace llvm::ilist_detail;
|
|
|
|
namespace {
|
|
|
|
struct Node;
|
|
|
|
struct TagA {};
|
|
struct TagB {};
|
|
struct ParentA {};
|
|
struct ParentB {};
|
|
|
|
TEST(IListNodeTest, Options) {
|
|
static_assert(
|
|
std::is_same_v<compute_node_options<Node>::type,
|
|
compute_node_options<Node, ilist_tag<void>>::type>,
|
|
"default tag is void");
|
|
static_assert(
|
|
!std::is_same_v<compute_node_options<Node, ilist_tag<TagA>>::type,
|
|
compute_node_options<Node, ilist_tag<void>>::type>,
|
|
"default tag is void, different from TagA");
|
|
static_assert(
|
|
!std::is_same_v<compute_node_options<Node, ilist_tag<TagA>>::type,
|
|
compute_node_options<Node, ilist_tag<TagB>>::type>,
|
|
"TagA is not TagB");
|
|
static_assert(
|
|
std::is_same_v<
|
|
compute_node_options<Node, ilist_sentinel_tracking<false>>::type,
|
|
compute_node_options<Node, ilist_sentinel_tracking<false>,
|
|
ilist_tag<void>>::type>,
|
|
"default tag is void, even with sentinel tracking off");
|
|
static_assert(
|
|
std::is_same_v<
|
|
compute_node_options<Node, ilist_sentinel_tracking<false>>::type,
|
|
compute_node_options<Node, ilist_tag<void>,
|
|
ilist_sentinel_tracking<false>>::type>,
|
|
"order shouldn't matter");
|
|
static_assert(
|
|
std::is_same_v<
|
|
compute_node_options<Node, ilist_sentinel_tracking<true>>::type,
|
|
compute_node_options<Node, ilist_sentinel_tracking<true>,
|
|
ilist_tag<void>>::type>,
|
|
"default tag is void, even with sentinel tracking on");
|
|
static_assert(
|
|
std::is_same_v<
|
|
compute_node_options<Node, ilist_sentinel_tracking<true>>::type,
|
|
compute_node_options<Node, ilist_tag<void>,
|
|
ilist_sentinel_tracking<true>>::type>,
|
|
"order shouldn't matter");
|
|
static_assert(
|
|
std::is_same_v<compute_node_options<Node, ilist_sentinel_tracking<true>,
|
|
ilist_tag<TagA>>::type,
|
|
compute_node_options<Node, ilist_tag<TagA>,
|
|
ilist_sentinel_tracking<true>>::type>,
|
|
"order shouldn't matter with real tags");
|
|
static_assert(
|
|
std::is_same_v<compute_node_options<Node>::type,
|
|
compute_node_options<Node, ilist_parent<void>>::type>,
|
|
"default parent is void");
|
|
static_assert(
|
|
!std::is_same_v<compute_node_options<Node, ilist_parent<ParentA>>::type,
|
|
compute_node_options<Node, ilist_parent<void>>::type>,
|
|
"ParentA is not void");
|
|
static_assert(
|
|
!std::is_same_v<compute_node_options<Node, ilist_parent<ParentA>>::type,
|
|
compute_node_options<Node, ilist_parent<ParentB>>::type>,
|
|
"ParentA is not ParentB");
|
|
}
|
|
|
|
} // end namespace
|