diff --git a/CMake/AbseilDll.cmake b/CMake/AbseilDll.cmake index 675ee8a4..2102ef5c 100644 --- a/CMake/AbseilDll.cmake +++ b/CMake/AbseilDll.cmake @@ -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" diff --git a/absl/base/BUILD.bazel b/absl/base/BUILD.bazel index 704468a5..5e67a651 100644 --- a/absl/base/BUILD.bazel +++ b/absl/base/BUILD.bazel @@ -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( diff --git a/absl/base/CMakeLists.txt b/absl/base/CMakeLists.txt index 091d3a7e..c98a63e6 100644 --- a/absl/base/CMakeLists.txt +++ b/absl/base/CMakeLists.txt @@ -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 diff --git a/absl/base/inline_variable_test.cc b/absl/base/inline_variable_test.cc deleted file mode 100644 index 37a40e1e..00000000 --- a/absl/base/inline_variable_test.cc +++ /dev/null @@ -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 - -#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::type>::value, - ""); -} - -} // namespace -} // namespace inline_variable_testing_internal -ABSL_NAMESPACE_END -} // namespace absl diff --git a/absl/base/inline_variable_test_a.cc b/absl/base/inline_variable_test_a.cc deleted file mode 100644 index f96a58d9..00000000 --- a/absl/base/inline_variable_test_a.cc +++ /dev/null @@ -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 diff --git a/absl/base/inline_variable_test_b.cc b/absl/base/inline_variable_test_b.cc deleted file mode 100644 index 038adc30..00000000 --- a/absl/base/inline_variable_test_b.cc +++ /dev/null @@ -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 diff --git a/absl/base/internal/cycleclock_config.h b/absl/base/internal/cycleclock_config.h index 191112b5..50a46978 100644 --- a/absl/base/internal/cycleclock_config.h +++ b/absl/base/internal/cycleclock_config.h @@ -18,7 +18,6 @@ #include #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 diff --git a/absl/base/internal/inline_variable.h b/absl/base/internal/inline_variable.h deleted file mode 100644 index 09daf0f5..00000000 --- a/absl/base/internal/inline_variable.h +++ /dev/null @@ -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 - -#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 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 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 \ - struct AbslInternalInlineVariableHolder##name { \ - static constexpr ::absl::internal::type_identity_t kInstance = \ - init; \ - }; \ - \ - template \ - constexpr ::absl::internal::type_identity_t \ - AbslInternalInlineVariableHolder##name::kInstance; \ - \ - static constexpr const ::absl::internal::type_identity_t& \ - 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_ diff --git a/absl/base/internal/inline_variable_testing.h b/absl/base/internal/inline_variable_testing.h deleted file mode 100644 index f3c81459..00000000 --- a/absl/base/internal/inline_variable_testing.h +++ /dev/null @@ -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_ diff --git a/absl/random/distributions.h b/absl/random/distributions.h index b6ade685..dced8950 100644 --- a/absl/random/distributions.h +++ b/absl/random/distributions.h @@ -50,7 +50,6 @@ #include #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(tag, bitgen, lo, hi) diff --git a/absl/types/internal/optional.h b/absl/types/internal/optional.h index 5731a5bc..660bdfc8 100644 --- a/absl/types/internal/optional.h +++ b/absl/types/internal/optional.h @@ -20,7 +20,6 @@ #include #include -#include "absl/base/internal/inline_variable.h" #include "absl/memory/memory.h" #include "absl/meta/type_traits.h" #include "absl/utility/utility.h" diff --git a/absl/types/internal/variant.h b/absl/types/internal/variant.h index 31cfe0ae..40574ae9 100644 --- a/absl/types/internal/variant.h +++ b/absl/types/internal/variant.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 variant; -ABSL_INTERNAL_INLINE_CONSTEXPR(size_t, variant_npos, static_cast(-1)); +inline constexpr size_t variant_npos = static_cast(-1); template 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 diff --git a/absl/types/optional.h b/absl/types/optional.h index 0d8f8704..97ac02e1 100644 --- a/absl/types/optional.h +++ b/absl/types/optional.h @@ -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 diff --git a/absl/utility/utility.h b/absl/utility/utility.h index 8f583d5a..9e37ee21 100644 --- a/absl/utility/utility.h +++ b/absl/utility/utility.h @@ -40,7 +40,6 @@ #include #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