[LLVM][NFC] remove unused fields
[llvm-complete.git] / unittests / Support / ThreadLocalTest.cpp
blob075d7d95b25b0270ad75a0e1b382147528743c5e
1 //===- llvm/unittest/Support/ThreadLocalTest.cpp - ThreadLocal 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 //===----------------------------------------------------------------------===//
9 #include "llvm/Support/ThreadLocal.h"
10 #include "gtest/gtest.h"
11 #include <type_traits>
13 using namespace llvm;
14 using namespace sys;
16 namespace {
18 class ThreadLocalTest : public ::testing::Test {
21 struct S {
22 int i;
25 TEST_F(ThreadLocalTest, Basics) {
26 ThreadLocal<const S> x;
28 static_assert(
29 std::is_const<std::remove_pointer<decltype(x.get())>::type>::value,
30 "ThreadLocal::get didn't return a pointer to const object");
32 EXPECT_EQ(nullptr, x.get());
34 S s;
35 x.set(&s);
36 EXPECT_EQ(&s, x.get());
38 x.erase();
39 EXPECT_EQ(nullptr, x.get());
41 ThreadLocal<S> y;
43 static_assert(
44 !std::is_const<std::remove_pointer<decltype(y.get())>::type>::value,
45 "ThreadLocal::get returned a pointer to const object");
47 EXPECT_EQ(nullptr, y.get());
49 y.set(&s);
50 EXPECT_EQ(&s, y.get());
52 y.erase();
53 EXPECT_EQ(nullptr, y.get());