Skip to content

Commit

Permalink
Export of internal Abseil changes
Browse files Browse the repository at this point in the history
--
62058c9c008e23c787f35c1a5fe05851046a71f1 by Abseil Team <absl-team@google.com>:

Fix some strange usage of INSTANTIATE_TEST_SUITE_P

PiperOrigin-RevId: 264185105

--
4400d84027d86415a2f9b81996ff22e7fd7aa30f by Derek Mauro <dmauro@google.com>:

Disable testing std::string_view from nullptr on GCC >= GCC9.

PiperOrigin-RevId: 264150587

--
656d5a742ba48d025589709fad33ddae4b02c620 by Matt Calabrese <calabrese@google.com>:

Fix `absl::any_cast` such that it properly works with qualifications.

PiperOrigin-RevId: 263843429

--
6ec89214a4ef2170bf069623a56ffd22863b748d by Abseil Team <absl-team@google.com>:

Use macros to enable inline constexpr variables in compare.h when the compiler supports the feature.

PiperOrigin-RevId: 263790677

--
a5171e0897195a0367fc08abce9504f813d027ff by Derek Mauro <dmauro@google.com>:

Add the Apache License to files that are missing it.

PiperOrigin-RevId: 263774164

--
19e09a7ce8a0aac0a7d534e1799e4d73b63a1bb5 by Abseil Team <absl-team@google.com>:

Update iter.position when moving up the tree in rebalance_after_delete.

This field isn't read after the first iteration in rebalance_after_delete, and I think it's not a correctness issue, but it is read in try_merge_or_rebalance and potentially affects rebalancing decisions so it can affect performance. There's also an extremely unlikely potential for undefined behavior due to signed integer overflow since this field is only ever incremented in try_merge_or_rebalance (and position is an int). Basically though, I just don't think it makes sense to have this invalid iterator floating around here.

PiperOrigin-RevId: 263770305
GitOrigin-RevId: 62058c9c008e23c787f35c1a5fe05851046a71f1
Change-Id: I1e2fb7cbfac7507dddedd181414ee35a5778f8f5
  • Loading branch information
Abseil Team authored and Xiaoyi Zhang committed Aug 19, 2019
1 parent 9a41ffd commit 0e7afdc
Show file tree
Hide file tree
Showing 15 changed files with 224 additions and 64 deletions.
16 changes: 16 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
#
# Copyright 2019 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.
#

workspace(name = "com_google_absl")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

Expand Down
1 change: 1 addition & 0 deletions absl/container/internal/btree.h
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,7 @@ auto btree<P>::rebalance_after_delete(iterator iter) -> iterator {
if (!merged) {
break;
}
iter.position = iter.node->position();
iter.node = iter.node->parent();
}

Expand Down
16 changes: 16 additions & 0 deletions absl/meta/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
#
# Copyright 2019 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.
#

load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load(
"//absl:copts/configure_copts.bzl",
Expand Down
16 changes: 16 additions & 0 deletions absl/random/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
#
# Copyright 2019 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.
#

# ABSL random-number generation libraries.

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
Expand Down
2 changes: 1 addition & 1 deletion absl/random/exponential_distribution_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ std::string ParamName(const ::testing::TestParamInfo<Param>& info) {
return absl::StrReplaceAll(name, {{"+", "_"}, {"-", "_"}, {".", "_"}});
}

INSTANTIATE_TEST_CASE_P(, ExponentialDistributionTests,
INSTANTIATE_TEST_CASE_P(All, ExponentialDistributionTests,
::testing::ValuesIn(GenParams()), ParamName);

// NOTE: absl::exponential_distribution is not guaranteed to be stable.
Expand Down
2 changes: 1 addition & 1 deletion absl/random/gaussian_distribution_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ std::string ParamName(const ::testing::TestParamInfo<Param>& info) {
return absl::StrReplaceAll(name, {{"+", "_"}, {"-", "_"}, {".", "_"}});
}

INSTANTIATE_TEST_SUITE_P(, GaussianDistributionTests,
INSTANTIATE_TEST_SUITE_P(All, GaussianDistributionTests,
::testing::ValuesIn(GenParams()), ParamName);

// NOTE: absl::gaussian_distribution is not guaranteed to be stable.
Expand Down
16 changes: 16 additions & 0 deletions absl/random/internal/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
#
# Copyright 2019 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.
#

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")

# Internal-only implementation classes for Abseil Random
Expand Down
2 changes: 1 addition & 1 deletion absl/random/log_uniform_int_distribution_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ std::string ParamName(
return absl::StrReplaceAll(name, {{"+", "_"}, {"-", "_"}, {".", "_"}});
}

INSTANTIATE_TEST_SUITE_P(, LogUniformIntChiSquaredTest,
INSTANTIATE_TEST_SUITE_P(All, LogUniformIntChiSquaredTest,
::testing::ValuesIn(GenParams()), ParamName);

// NOTE: absl::log_uniform_int_distribution is not guaranteed to be stable.
Expand Down
4 changes: 2 additions & 2 deletions absl/random/poisson_distribution_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ std::string ZParamName(const ::testing::TestParamInfo<ZParam>& info) {
return absl::StrReplaceAll(name, {{"+", "_"}, {"-", "_"}, {".", "_"}});
}

INSTANTIATE_TEST_SUITE_P(, PoissonDistributionZTest,
INSTANTIATE_TEST_SUITE_P(All, PoissonDistributionZTest,
::testing::ValuesIn(GetZParams()), ZParamName);

// The PoissonDistributionChiSquaredTest class provides a basic test framework
Expand Down Expand Up @@ -468,7 +468,7 @@ TEST_P(PoissonDistributionChiSquaredTest, AbslPoissonDistribution) {
EXPECT_LE(failures, 4);
}

INSTANTIATE_TEST_SUITE_P(, PoissonDistributionChiSquaredTest,
INSTANTIATE_TEST_SUITE_P(All, PoissonDistributionChiSquaredTest,
::testing::Values(0.5, 1.0, 2.0, 10.0, 50.0, 51.0,
200.0));

Expand Down
8 changes: 5 additions & 3 deletions absl/strings/string_view_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -822,15 +822,17 @@ TEST(StringViewTest, FrontBackSingleChar) {
// "read of dereferenced null pointer is not allowed in a constant expression".
// At run time, the behavior of `std::char_traits::length()` on `nullptr` is
// undefined by the standard and usually results in crash with libc++.
// GCC also started rejected this in libstdc++ starting in GCC9.
// In MSVC, creating a constexpr string_view from nullptr also triggers an
// "unevaluable pointer value" error. This compiler implementation conforms
// to the standard, but `absl::string_view` implements a different
// behavior for historical reasons. We work around tests that construct
// `string_view` from `nullptr` when using libc++.
#if !defined(ABSL_HAVE_STD_STRING_VIEW) || \
(!defined(_LIBCPP_VERSION) && !defined(_MSC_VER))
#if !defined(ABSL_HAVE_STD_STRING_VIEW) || \
(!(defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE >= 9) && \
!defined(_LIBCPP_VERSION) && !defined(_MSC_VER))
#define ABSL_HAVE_STRING_VIEW_FROM_NULLPTR 1
#endif // !defined(ABSL_HAVE_STD_STRING_VIEW) || !defined(_LIBCPP_VERSION)
#endif

TEST(StringViewTest, NULLInput) {
absl::string_view s;
Expand Down
12 changes: 8 additions & 4 deletions absl/types/any.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,18 +515,22 @@ ValueType any_cast(any&& operand) {
// Description at the declaration site (top of file).
template <typename T>
const T* any_cast(const any* operand) noexcept {
return operand && operand->GetObjTypeId() == any::IdForType<T>()
using U =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
return operand && operand->GetObjTypeId() == any::IdForType<U>()
? std::addressof(
static_cast<const any::Obj<T>*>(operand->obj_.get())->value)
static_cast<const any::Obj<U>*>(operand->obj_.get())->value)
: nullptr;
}

// Description at the declaration site (top of file).
template <typename T>
T* any_cast(any* operand) noexcept {
return operand && operand->GetObjTypeId() == any::IdForType<T>()
using U =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
return operand && operand->GetObjTypeId() == any::IdForType<U>()
? std::addressof(
static_cast<any::Obj<T>*>(operand->obj_.get())->value)
static_cast<any::Obj<U>*>(operand->obj_.get())->value)
: nullptr;
}

Expand Down
Loading

0 comments on commit 0e7afdc

Please sign in to comment.