mirror of
https://github.com/abseil/abseil-cpp.git
synced 2026-06-04 12:07:05 +08:00
Delete absl/base/internal/inline_variable.h
PiperOrigin-RevId: 728684812 Change-Id: If4e2d0fed045c1cb312a48f250d5ebb1aaa1b41f
This commit is contained in:
committed by
Copybara-Service
parent
a6fccf59b4
commit
e78a8ce497
@@ -22,7 +22,6 @@ set(ABSL_INTERNAL_DLL_FILES
|
||||
"base/internal/hide_ptr.h"
|
||||
"base/internal/identity.h"
|
||||
"base/internal/iterator_traits.h"
|
||||
"base/internal/inline_variable.h"
|
||||
"base/internal/low_level_alloc.cc"
|
||||
"base/internal/low_level_alloc.h"
|
||||
"base/internal/low_level_scheduling.h"
|
||||
|
||||
@@ -230,7 +230,6 @@ cc_library(
|
||||
hdrs = [
|
||||
"internal/hide_ptr.h",
|
||||
"internal/identity.h",
|
||||
"internal/inline_variable.h",
|
||||
"internal/scheduling_mode.h",
|
||||
],
|
||||
copts = ABSL_DEFAULT_COPTS,
|
||||
@@ -463,24 +462,6 @@ cc_test(
|
||||
],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "inline_variable_test",
|
||||
size = "small",
|
||||
srcs = [
|
||||
"inline_variable_test.cc",
|
||||
"inline_variable_test_a.cc",
|
||||
"inline_variable_test_b.cc",
|
||||
"internal/inline_variable_testing.h",
|
||||
],
|
||||
copts = ABSL_TEST_COPTS,
|
||||
linkopts = ABSL_DEFAULT_LINKOPTS,
|
||||
deps = [
|
||||
":base_internal",
|
||||
"@googletest//:gtest",
|
||||
"@googletest//:gtest_main",
|
||||
],
|
||||
)
|
||||
|
||||
# Common test library made available for use in non-absl code that overrides
|
||||
# AbslInternalSpinLockDelay and AbslInternalSpinLockWake.
|
||||
cc_library(
|
||||
|
||||
@@ -216,7 +216,6 @@ absl_cc_library(
|
||||
HDRS
|
||||
"internal/hide_ptr.h"
|
||||
"internal/identity.h"
|
||||
"internal/inline_variable.h"
|
||||
"internal/scheduling_mode.h"
|
||||
COPTS
|
||||
${ABSL_DEFAULT_COPTS}
|
||||
@@ -424,21 +423,6 @@ absl_cc_test(
|
||||
GTest::gtest_main
|
||||
)
|
||||
|
||||
absl_cc_test(
|
||||
NAME
|
||||
inline_variable_test
|
||||
SRCS
|
||||
"internal/inline_variable_testing.h"
|
||||
"inline_variable_test.cc"
|
||||
"inline_variable_test_a.cc"
|
||||
"inline_variable_test_b.cc"
|
||||
COPTS
|
||||
${ABSL_TEST_COPTS}
|
||||
DEPS
|
||||
absl::base_internal
|
||||
GTest::gtest_main
|
||||
)
|
||||
|
||||
# Internal-only target, do not depend on directly.
|
||||
absl_cc_library(
|
||||
NAME
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
// Copyright 2017 The Abseil Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include "absl/base/internal/inline_variable.h"
|
||||
#include "absl/base/internal/inline_variable_testing.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace absl {
|
||||
ABSL_NAMESPACE_BEGIN
|
||||
namespace inline_variable_testing_internal {
|
||||
namespace {
|
||||
|
||||
TEST(InlineVariableTest, Constexpr) {
|
||||
static_assert(inline_variable_foo.value == 5, "");
|
||||
static_assert(other_inline_variable_foo.value == 5, "");
|
||||
static_assert(inline_variable_int == 5, "");
|
||||
static_assert(other_inline_variable_int == 5, "");
|
||||
}
|
||||
|
||||
TEST(InlineVariableTest, DefaultConstructedIdentityEquality) {
|
||||
EXPECT_EQ(get_foo_a().value, 5);
|
||||
EXPECT_EQ(get_foo_b().value, 5);
|
||||
EXPECT_EQ(&get_foo_a(), &get_foo_b());
|
||||
}
|
||||
|
||||
TEST(InlineVariableTest, DefaultConstructedIdentityInequality) {
|
||||
EXPECT_NE(&inline_variable_foo, &other_inline_variable_foo);
|
||||
}
|
||||
|
||||
TEST(InlineVariableTest, InitializedIdentityEquality) {
|
||||
EXPECT_EQ(get_int_a(), 5);
|
||||
EXPECT_EQ(get_int_b(), 5);
|
||||
EXPECT_EQ(&get_int_a(), &get_int_b());
|
||||
}
|
||||
|
||||
TEST(InlineVariableTest, InitializedIdentityInequality) {
|
||||
EXPECT_NE(&inline_variable_int, &other_inline_variable_int);
|
||||
}
|
||||
|
||||
TEST(InlineVariableTest, FunPtrType) {
|
||||
static_assert(
|
||||
std::is_same<void(*)(),
|
||||
std::decay<decltype(inline_variable_fun_ptr)>::type>::value,
|
||||
"");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace inline_variable_testing_internal
|
||||
ABSL_NAMESPACE_END
|
||||
} // namespace absl
|
||||
@@ -1,27 +0,0 @@
|
||||
// Copyright 2017 The Abseil Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "absl/base/internal/inline_variable_testing.h"
|
||||
|
||||
namespace absl {
|
||||
ABSL_NAMESPACE_BEGIN
|
||||
namespace inline_variable_testing_internal {
|
||||
|
||||
const Foo& get_foo_a() { return inline_variable_foo; }
|
||||
|
||||
const int& get_int_a() { return inline_variable_int; }
|
||||
|
||||
} // namespace inline_variable_testing_internal
|
||||
ABSL_NAMESPACE_END
|
||||
} // namespace absl
|
||||
@@ -1,27 +0,0 @@
|
||||
// Copyright 2017 The Abseil Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "absl/base/internal/inline_variable_testing.h"
|
||||
|
||||
namespace absl {
|
||||
ABSL_NAMESPACE_BEGIN
|
||||
namespace inline_variable_testing_internal {
|
||||
|
||||
const Foo& get_foo_b() { return inline_variable_foo; }
|
||||
|
||||
const int& get_int_b() { return inline_variable_int; }
|
||||
|
||||
} // namespace inline_variable_testing_internal
|
||||
ABSL_NAMESPACE_END
|
||||
} // namespace absl
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <cstdint>
|
||||
|
||||
#include "absl/base/config.h"
|
||||
#include "absl/base/internal/inline_variable.h"
|
||||
#include "absl/base/internal/unscaledcycleclock_config.h"
|
||||
|
||||
namespace absl {
|
||||
@@ -31,22 +30,23 @@ namespace base_internal {
|
||||
// Not debug mode and the UnscaledCycleClock frequency is the CPU
|
||||
// frequency. Scale the CycleClock to prevent overflow if someone
|
||||
// tries to represent the time as cycles since the Unix epoch.
|
||||
ABSL_INTERNAL_INLINE_CONSTEXPR(int32_t, kCycleClockShift, 1);
|
||||
inline constexpr int32_t kCycleClockShift = 1;
|
||||
#else
|
||||
// Not debug mode and the UnscaledCycleClock isn't operating at the
|
||||
// raw CPU frequency. There is no need to do any scaling, so don't
|
||||
// needlessly sacrifice precision.
|
||||
ABSL_INTERNAL_INLINE_CONSTEXPR(int32_t, kCycleClockShift, 0);
|
||||
inline constexpr int32_t kCycleClockShift = 0;
|
||||
#endif
|
||||
#else // NDEBUG
|
||||
// In debug mode use a different shift to discourage depending on a
|
||||
// particular shift value.
|
||||
ABSL_INTERNAL_INLINE_CONSTEXPR(int32_t, kCycleClockShift, 2);
|
||||
inline constexpr int32_t kCycleClockShift = 2;
|
||||
#endif // NDEBUG
|
||||
|
||||
ABSL_INTERNAL_INLINE_CONSTEXPR(double, kCycleClockFrequencyScale,
|
||||
1.0 / (1 << kCycleClockShift));
|
||||
#endif // ABSL_USE_UNSCALED_CYCLECLOC
|
||||
inline constexpr double kCycleClockFrequencyScale =
|
||||
1.0 / (1 << kCycleClockShift);
|
||||
|
||||
#endif // ABSL_USE_UNSCALED_CYCLECLOCK
|
||||
|
||||
} // namespace base_internal
|
||||
ABSL_NAMESPACE_END
|
||||
|
||||
@@ -1,108 +0,0 @@
|
||||
// Copyright 2017 The Abseil Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef ABSL_BASE_INTERNAL_INLINE_VARIABLE_H_
|
||||
#define ABSL_BASE_INTERNAL_INLINE_VARIABLE_H_
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include "absl/base/internal/identity.h"
|
||||
|
||||
// File:
|
||||
// This file define a macro that allows the creation of or emulation of C++17
|
||||
// inline variables based on whether or not the feature is supported.
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Macro: ABSL_INTERNAL_INLINE_CONSTEXPR(type, name, init)
|
||||
//
|
||||
// Description:
|
||||
// Expands to the equivalent of an inline constexpr instance of the specified
|
||||
// `type` and `name`, initialized to the value `init`. If the compiler being
|
||||
// used is detected as supporting actual inline variables as a language
|
||||
// feature, then the macro expands to an actual inline variable definition.
|
||||
//
|
||||
// Requires:
|
||||
// `type` is a type that is usable in an extern variable declaration.
|
||||
//
|
||||
// Requires: `name` is a valid identifier
|
||||
//
|
||||
// Requires:
|
||||
// `init` is an expression that can be used in the following definition:
|
||||
// constexpr type name = init;
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// // Equivalent to: `inline constexpr size_t variant_npos = -1;`
|
||||
// ABSL_INTERNAL_INLINE_CONSTEXPR(size_t, variant_npos, -1);
|
||||
//
|
||||
// Differences in implementation:
|
||||
// For a direct, language-level inline variable, decltype(name) will be the
|
||||
// type that was specified along with const qualification, whereas for
|
||||
// emulated inline variables, decltype(name) may be different (in practice
|
||||
// it will likely be a reference type).
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __cpp_inline_variables
|
||||
|
||||
// Clang's -Wmissing-variable-declarations option erroneously warned that
|
||||
// inline constexpr objects need to be pre-declared. This has now been fixed,
|
||||
// but we will need to support this workaround for people building with older
|
||||
// versions of clang.
|
||||
//
|
||||
// Bug: https://bugs.llvm.org/show_bug.cgi?id=35862
|
||||
//
|
||||
// Note:
|
||||
// type_identity_t is used here so that the const and name are in the
|
||||
// appropriate place for pointer types, reference types, function pointer
|
||||
// types, etc..
|
||||
#if defined(__clang__)
|
||||
#define ABSL_INTERNAL_EXTERN_DECL(type, name) \
|
||||
extern const ::absl::internal::type_identity_t<type> name;
|
||||
#else // Otherwise, just define the macro to do nothing.
|
||||
#define ABSL_INTERNAL_EXTERN_DECL(type, name)
|
||||
#endif // defined(__clang__)
|
||||
|
||||
// See above comment at top of file for details.
|
||||
#define ABSL_INTERNAL_INLINE_CONSTEXPR(type, name, init) \
|
||||
ABSL_INTERNAL_EXTERN_DECL(type, name) \
|
||||
inline constexpr ::absl::internal::type_identity_t<type> name = init
|
||||
|
||||
#else
|
||||
|
||||
// See above comment at top of file for details.
|
||||
//
|
||||
// Note:
|
||||
// type_identity_t is used here so that the const and name are in the
|
||||
// appropriate place for pointer types, reference types, function pointer
|
||||
// types, etc..
|
||||
#define ABSL_INTERNAL_INLINE_CONSTEXPR(var_type, name, init) \
|
||||
template <class /*AbslInternalDummy*/ = void> \
|
||||
struct AbslInternalInlineVariableHolder##name { \
|
||||
static constexpr ::absl::internal::type_identity_t<var_type> kInstance = \
|
||||
init; \
|
||||
}; \
|
||||
\
|
||||
template <class AbslInternalDummy> \
|
||||
constexpr ::absl::internal::type_identity_t<var_type> \
|
||||
AbslInternalInlineVariableHolder##name<AbslInternalDummy>::kInstance; \
|
||||
\
|
||||
static constexpr const ::absl::internal::type_identity_t<var_type>& \
|
||||
name = /* NOLINT */ \
|
||||
AbslInternalInlineVariableHolder##name<>::kInstance; \
|
||||
static_assert(sizeof(void (*)(decltype(name))) != 0, \
|
||||
"Silence unused variable warnings.")
|
||||
|
||||
#endif // __cpp_inline_variables
|
||||
|
||||
#endif // ABSL_BASE_INTERNAL_INLINE_VARIABLE_H_
|
||||
@@ -1,46 +0,0 @@
|
||||
// Copyright 2017 The Abseil Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef ABSL_BASE_INTERNAL_INLINE_VARIABLE_TESTING_H_
|
||||
#define ABSL_BASE_INTERNAL_INLINE_VARIABLE_TESTING_H_
|
||||
|
||||
#include "absl/base/internal/inline_variable.h"
|
||||
|
||||
namespace absl {
|
||||
ABSL_NAMESPACE_BEGIN
|
||||
namespace inline_variable_testing_internal {
|
||||
|
||||
struct Foo {
|
||||
int value = 5;
|
||||
};
|
||||
|
||||
ABSL_INTERNAL_INLINE_CONSTEXPR(Foo, inline_variable_foo, {});
|
||||
ABSL_INTERNAL_INLINE_CONSTEXPR(Foo, other_inline_variable_foo, {});
|
||||
|
||||
ABSL_INTERNAL_INLINE_CONSTEXPR(int, inline_variable_int, 5);
|
||||
ABSL_INTERNAL_INLINE_CONSTEXPR(int, other_inline_variable_int, 5);
|
||||
|
||||
ABSL_INTERNAL_INLINE_CONSTEXPR(void(*)(), inline_variable_fun_ptr, nullptr);
|
||||
|
||||
const Foo& get_foo_a();
|
||||
const Foo& get_foo_b();
|
||||
|
||||
const int& get_int_a();
|
||||
const int& get_int_b();
|
||||
|
||||
} // namespace inline_variable_testing_internal
|
||||
ABSL_NAMESPACE_END
|
||||
} // namespace absl
|
||||
|
||||
#endif // ABSL_BASE_INTERNAL_INLINE_VARIABLE_TESTING_H_
|
||||
@@ -50,7 +50,6 @@
|
||||
#include <type_traits>
|
||||
|
||||
#include "absl/base/config.h"
|
||||
#include "absl/base/internal/inline_variable.h"
|
||||
#include "absl/meta/type_traits.h"
|
||||
#include "absl/random/bernoulli_distribution.h"
|
||||
#include "absl/random/beta_distribution.h"
|
||||
@@ -68,13 +67,12 @@
|
||||
namespace absl {
|
||||
ABSL_NAMESPACE_BEGIN
|
||||
|
||||
ABSL_INTERNAL_INLINE_CONSTEXPR(IntervalClosedClosedTag, IntervalClosedClosed,
|
||||
{});
|
||||
ABSL_INTERNAL_INLINE_CONSTEXPR(IntervalClosedClosedTag, IntervalClosed, {});
|
||||
ABSL_INTERNAL_INLINE_CONSTEXPR(IntervalClosedOpenTag, IntervalClosedOpen, {});
|
||||
ABSL_INTERNAL_INLINE_CONSTEXPR(IntervalOpenOpenTag, IntervalOpenOpen, {});
|
||||
ABSL_INTERNAL_INLINE_CONSTEXPR(IntervalOpenOpenTag, IntervalOpen, {});
|
||||
ABSL_INTERNAL_INLINE_CONSTEXPR(IntervalOpenClosedTag, IntervalOpenClosed, {});
|
||||
inline constexpr IntervalClosedClosedTag IntervalClosedClosed = {};
|
||||
inline constexpr IntervalClosedClosedTag IntervalClosed = {};
|
||||
inline constexpr IntervalClosedOpenTag IntervalClosedOpen = {};
|
||||
inline constexpr IntervalOpenOpenTag IntervalOpenOpen = {};
|
||||
inline constexpr IntervalOpenOpenTag IntervalOpen = {};
|
||||
inline constexpr IntervalOpenClosedTag IntervalOpenClosed = {};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// absl::Uniform<T>(tag, bitgen, lo, hi)
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include "absl/base/internal/inline_variable.h"
|
||||
#include "absl/memory/memory.h"
|
||||
#include "absl/meta/type_traits.h"
|
||||
#include "absl/utility/utility.h"
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
|
||||
#include "absl/base/config.h"
|
||||
#include "absl/base/internal/identity.h"
|
||||
#include "absl/base/internal/inline_variable.h"
|
||||
#include "absl/base/macros.h"
|
||||
#include "absl/base/optimization.h"
|
||||
#include "absl/meta/type_traits.h"
|
||||
@@ -45,7 +44,7 @@ ABSL_NAMESPACE_BEGIN
|
||||
template <class... Types>
|
||||
class variant;
|
||||
|
||||
ABSL_INTERNAL_INLINE_CONSTEXPR(size_t, variant_npos, static_cast<size_t>(-1));
|
||||
inline constexpr size_t variant_npos = static_cast<size_t>(-1);
|
||||
|
||||
template <class T>
|
||||
struct variant_size;
|
||||
@@ -288,7 +287,7 @@ struct ReachableSwitchCase {
|
||||
// power of 2 is because the number was picked to correspond to a power of 2
|
||||
// amount of "normal" alternatives, plus one for the possibility of the user
|
||||
// providing "monostate" in addition to the more natural alternatives.
|
||||
ABSL_INTERNAL_INLINE_CONSTEXPR(std::size_t, MaxUnrolledVisitCases, 33);
|
||||
inline constexpr std::size_t MaxUnrolledVisitCases = 33;
|
||||
|
||||
// Note: The default-definition is for unreachable cases.
|
||||
template <bool IsReachable>
|
||||
|
||||
@@ -62,7 +62,6 @@ ABSL_NAMESPACE_END
|
||||
|
||||
#include "absl/base/attributes.h"
|
||||
#include "absl/base/nullability.h"
|
||||
#include "absl/base/internal/inline_variable.h"
|
||||
#include "absl/meta/type_traits.h"
|
||||
#include "absl/types/bad_optional_access.h"
|
||||
#include "absl/types/internal/optional.h"
|
||||
@@ -83,8 +82,7 @@ struct nullopt_t {
|
||||
//
|
||||
// A tag constant of type `absl::nullopt_t` used to indicate an empty
|
||||
// `absl::optional` in certain functions, such as construction or assignment.
|
||||
ABSL_INTERNAL_INLINE_CONSTEXPR(nullopt_t, nullopt,
|
||||
nullopt_t(optional_internal::init_t()));
|
||||
inline constexpr nullopt_t nullopt = nullopt_t(optional_internal::init_t());
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// absl::optional
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
#include <utility>
|
||||
|
||||
#include "absl/base/config.h"
|
||||
#include "absl/base/internal/inline_variable.h"
|
||||
#include "absl/meta/type_traits.h"
|
||||
|
||||
namespace absl {
|
||||
@@ -93,7 +92,7 @@ using std::in_place;
|
||||
// `std::in_place_t`.
|
||||
struct in_place_t {};
|
||||
|
||||
ABSL_INTERNAL_INLINE_CONSTEXPR(in_place_t, in_place, {});
|
||||
inline constexpr in_place_t in_place = {};
|
||||
|
||||
#endif // ABSL_USES_STD_OPTIONAL
|
||||
|
||||
|
||||
Reference in New Issue
Block a user