Skip to content

Commit 4167eab

Browse files
Abseil Teamvslashg
authored andcommitted
Export of internal Abseil changes
-- 506fa3e10b3d8399ad937c32ecea26d1ad4e62bb by Abseil Team <[email protected]>: Disable ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE when GCC < 8.2.0 is used with libc++ PiperOrigin-RevId: 399707056 -- 656b7c7cee87f46a4bc7953618796f82da08e62c by Derek Mauro <[email protected]>: Remove the MSVC flag implementation from flag.h to help clarify that methods on absl::Flag<T> are not part of the public API PiperOrigin-RevId: 399584678 -- a92a9bc156303bc663b84c4b704891ec8f67e333 by Abseil Team <[email protected]>: Get rid of MemcpyIfAllowed while continuing to suppress erroneous warnings PiperOrigin-RevId: 399468864 -- 5f9a66895f707ba001fb51b88c0c6025f8c872a3 by Abseil Team <[email protected]>: Use feature testing to check for availability of invoke_result. Feature testing should be available by C++20, which removes invoke_result. https://en.cppreference.com/w/cpp/feature_test PiperOrigin-RevId: 399447373 -- 946c0a502b4499dbfcabf1ab93ddde0048288fb4 by CJ Johnson <[email protected]>: Add rvalue-reference qualifier to the Commit method on ConstructionTransaction PiperOrigin-RevId: 399442206 -- 726a4d036eff49aeb6fd0ca2b1775699b6844395 by Greg Falcon <[email protected]>: Internal change PiperOrigin-RevId: 399441870 -- 1df6d3f659b88dbac13c3d8e13db23bb3844ece2 by Abseil Team <[email protected]>: Clang-format whitespace changes PiperOrigin-RevId: 399281271 -- 4a828cde95a07421d699ebac775b37810624214f by Derek Mauro <[email protected]>: Internal change PiperOrigin-RevId: 399234071 -- e520c72b34ba2f98668c889139001f8276243d31 by Greg Falcon <[email protected]>: Import of CCTZ from GitHub. PiperOrigin-RevId: 399233662 GitOrigin-RevId: 506fa3e10b3d8399ad937c32ecea26d1ad4e62bb Change-Id: I92b9176d2387c08eb167f9268efa78b55b8e09c2
1 parent 7143e49 commit 4167eab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+158
-162
lines changed

absl/base/config.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,17 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
243243
//
244244
// Checks whether `std::is_trivially_copy_assignable<T>` is supported.
245245

246-
// Notes: Clang with libc++ supports these features, as does gcc >= 5.1 with
247-
// either libc++ or libstdc++, and Visual Studio (but not NVCC).
246+
// Notes: Clang with libc++ supports these features, as does gcc >= 7.4 with
247+
// libstdc++, or gcc >= 8.2 with libc++, and Visual Studio (but not NVCC).
248248
#if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE)
249249
#error ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE cannot be directly set
250250
#elif defined(ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE)
251251
#error ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE cannot directly set
252-
#elif (defined(__clang__) && defined(_LIBCPP_VERSION)) || \
253-
(!defined(__clang__) && ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(7, 4) && \
254-
(defined(_LIBCPP_VERSION) || defined(__GLIBCXX__))) || \
252+
#elif (defined(__clang__) && defined(_LIBCPP_VERSION)) || \
253+
(!defined(__clang__) && \
254+
((ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(7, 4) && defined(__GLIBCXX__)) || \
255+
(ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(8, 2) && \
256+
defined(_LIBCPP_VERSION)))) || \
255257
(defined(_MSC_VER) && !defined(__NVCC__))
256258
#define ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE 1
257259
#define ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 1

absl/container/internal/inlined_vector.h

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,6 @@ struct MallocAdapter {
126126
}
127127
};
128128

129-
// If kUseMemcpy is true, memcpy(dst, src, n); else do nothing.
130-
// Useful to avoid compiler warnings when memcpy() is used for T values
131-
// that are not trivially copyable in non-reachable code.
132-
template <bool kUseMemcpy>
133-
inline void MemcpyIfAllowed(void* dst, const void* src, size_t n);
134-
135-
// memcpy when allowed.
136-
template <>
137-
inline void MemcpyIfAllowed<true>(void* dst, const void* src, size_t n) {
138-
memcpy(dst, src, n);
139-
}
140-
141-
// Do nothing for types that are not memcpy-able. This function is only
142-
// called from non-reachable branches.
143-
template <>
144-
inline void MemcpyIfAllowed<false>(void*, const void*, size_t) {}
145-
146129
template <typename A, typename ValueAdapter>
147130
void ConstructElements(NoTypeDeduction<A>& allocator,
148131
Pointer<A> construct_first, ValueAdapter& values,
@@ -288,7 +271,7 @@ class ConstructionTransaction {
288271
GetData() = data;
289272
GetSize() = size;
290273
}
291-
void Commit() {
274+
void Commit() && {
292275
GetData() = nullptr;
293276
GetSize() = 0;
294277
}
@@ -511,7 +494,8 @@ void Storage<T, N, A>::InitFrom(const Storage& other) {
511494
src = other.GetAllocatedData();
512495
}
513496
if (IsMemcpyOk<A>::value) {
514-
MemcpyIfAllowed<IsMemcpyOk<A>::value>(dst, src, sizeof(dst[0]) * n);
497+
std::memcpy(reinterpret_cast<char*>(dst),
498+
reinterpret_cast<const char*>(src), n * sizeof(ValueType<A>));
515499
} else {
516500
auto values = IteratorValueAdapter<A, ConstPointer<A>>(src);
517501
ConstructElements<A>(GetAllocator(), dst, values, n);
@@ -628,7 +612,7 @@ auto Storage<T, N, A>::Resize(ValueAdapter values, SizeType<A> new_size)
628612
ConstructElements<A>(alloc, new_data, move_values, size);
629613

630614
DestroyElements<A>(alloc, base, size);
631-
construction_tx.Commit();
615+
std::move(construction_tx).Commit();
632616
DeallocateIfAllocated();
633617
SetAllocation(std::move(allocation_tx).Release());
634618
SetIsAllocated();
@@ -668,8 +652,8 @@ auto Storage<T, N, A>::Insert(ConstIterator<A> pos, ValueAdapter values,
668652

669653
DestroyElements<A>(GetAllocator(), storage_view.data, storage_view.size);
670654

671-
construction_tx.Commit();
672-
move_construction_tx.Commit();
655+
std::move(construction_tx).Commit();
656+
std::move(move_construction_tx).Commit();
673657
DeallocateIfAllocated();
674658
SetAllocation(std::move(allocation_tx).Release());
675659

@@ -721,7 +705,7 @@ auto Storage<T, N, A>::Insert(ConstIterator<A> pos, ValueAdapter values,
721705
ConstructElements<A>(GetAllocator(), insert_construction.data(), values,
722706
insert_construction.size());
723707

724-
move_construction_tx.Commit();
708+
std::move(move_construction_tx).Commit();
725709

726710
AddSize(insert_count);
727711
return Iterator<A>(storage_view.data + insert_index);

absl/flags/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ cc_library(
217217
name = "flag",
218218
srcs = [
219219
"flag.cc",
220+
"internal/flag_msvc.inc",
220221
],
221222
hdrs = [
222223
"declare.h",

absl/flags/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ absl_cc_library(
202202
HDRS
203203
"declare.h"
204204
"flag.h"
205+
"internal/flag_msvc.inc"
205206
COPTS
206207
${ABSL_DEFAULT_COPTS}
207208
LINKOPTS

absl/flags/flag.h

Lines changed: 1 addition & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -71,101 +71,7 @@ ABSL_NAMESPACE_BEGIN
7171
template <typename T>
7272
using Flag = flags_internal::Flag<T>;
7373
#else
74-
// MSVC debug builds do not implement initialization with constexpr constructors
75-
// correctly. To work around this we add a level of indirection, so that the
76-
// class `absl::Flag` contains an `internal::Flag*` (instead of being an alias
77-
// to that class) and dynamically allocates an instance when necessary. We also
78-
// forward all calls to internal::Flag methods via trampoline methods. In this
79-
// setup the `absl::Flag` class does not have constructor and virtual methods,
80-
// all the data members are public and thus MSVC is able to initialize it at
81-
// link time. To deal with multiple threads accessing the flag for the first
82-
// time concurrently we use an atomic boolean indicating if flag object is
83-
// initialized. We also employ the double-checked locking pattern where the
84-
// second level of protection is a global Mutex, so if two threads attempt to
85-
// construct the flag concurrently only one wins.
86-
// This solution is based on a recomendation here:
87-
// https://developercommunity.visualstudio.com/content/problem/336946/class-with-constexpr-constructor-not-using-static.html?childToView=648454#comment-648454
88-
89-
namespace flags_internal {
90-
absl::Mutex* GetGlobalConstructionGuard();
91-
} // namespace flags_internal
92-
93-
template <typename T>
94-
class Flag {
95-
public:
96-
// No constructor and destructor to ensure this is an aggregate type.
97-
// Visual Studio 2015 still requires the constructor for class to be
98-
// constexpr initializable.
99-
#if _MSC_VER <= 1900
100-
constexpr Flag(const char* name, const char* filename,
101-
const flags_internal::HelpGenFunc help_gen,
102-
const flags_internal::FlagDfltGenFunc default_value_gen)
103-
: name_(name),
104-
filename_(filename),
105-
help_gen_(help_gen),
106-
default_value_gen_(default_value_gen),
107-
inited_(false),
108-
impl_(nullptr) {}
109-
#endif
110-
111-
flags_internal::Flag<T>& GetImpl() const {
112-
if (!inited_.load(std::memory_order_acquire)) {
113-
absl::MutexLock l(flags_internal::GetGlobalConstructionGuard());
114-
115-
if (inited_.load(std::memory_order_acquire)) {
116-
return *impl_;
117-
}
118-
119-
impl_ = new flags_internal::Flag<T>(
120-
name_, filename_,
121-
{flags_internal::FlagHelpMsg(help_gen_),
122-
flags_internal::FlagHelpKind::kGenFunc},
123-
{flags_internal::FlagDefaultSrc(default_value_gen_),
124-
flags_internal::FlagDefaultKind::kGenFunc});
125-
inited_.store(true, std::memory_order_release);
126-
}
127-
128-
return *impl_;
129-
}
130-
131-
// Public methods of `absl::Flag<T>` are NOT part of the Abseil Flags API.
132-
// See https://abseil.io/docs/cpp/guides/flags
133-
bool IsRetired() const { return GetImpl().IsRetired(); }
134-
absl::string_view Name() const { return GetImpl().Name(); }
135-
std::string Help() const { return GetImpl().Help(); }
136-
bool IsModified() const { return GetImpl().IsModified(); }
137-
bool IsSpecifiedOnCommandLine() const {
138-
return GetImpl().IsSpecifiedOnCommandLine();
139-
}
140-
std::string Filename() const { return GetImpl().Filename(); }
141-
std::string DefaultValue() const { return GetImpl().DefaultValue(); }
142-
std::string CurrentValue() const { return GetImpl().CurrentValue(); }
143-
template <typename U>
144-
inline bool IsOfType() const {
145-
return GetImpl().template IsOfType<U>();
146-
}
147-
T Get() const {
148-
return flags_internal::FlagImplPeer::InvokeGet<T>(GetImpl());
149-
}
150-
void Set(const T& v) {
151-
flags_internal::FlagImplPeer::InvokeSet(GetImpl(), v);
152-
}
153-
void InvokeCallback() { GetImpl().InvokeCallback(); }
154-
155-
const CommandLineFlag& Reflect() const {
156-
return flags_internal::FlagImplPeer::InvokeReflect(GetImpl());
157-
}
158-
159-
// The data members are logically private, but they need to be public for
160-
// this to be an aggregate type.
161-
const char* name_;
162-
const char* filename_;
163-
const flags_internal::HelpGenFunc help_gen_;
164-
const flags_internal::FlagDfltGenFunc default_value_gen_;
165-
166-
mutable std::atomic<bool> inited_;
167-
mutable flags_internal::Flag<T>* impl_;
168-
};
74+
#include "absl/flags/internal/flag_msvc.inc"
16975
#endif
17076

17177
// GetFlag()

absl/flags/internal/flag_msvc.inc

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
//
2+
// Copyright 2021 The Abseil Authors.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// https://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
// Do not include this file directly.
17+
// Include absl/flags/flag.h instead.
18+
19+
// MSVC debug builds do not implement initialization with constexpr constructors
20+
// correctly. To work around this we add a level of indirection, so that the
21+
// class `absl::Flag` contains an `internal::Flag*` (instead of being an alias
22+
// to that class) and dynamically allocates an instance when necessary. We also
23+
// forward all calls to internal::Flag methods via trampoline methods. In this
24+
// setup the `absl::Flag` class does not have constructor and virtual methods,
25+
// all the data members are public and thus MSVC is able to initialize it at
26+
// link time. To deal with multiple threads accessing the flag for the first
27+
// time concurrently we use an atomic boolean indicating if flag object is
28+
// initialized. We also employ the double-checked locking pattern where the
29+
// second level of protection is a global Mutex, so if two threads attempt to
30+
// construct the flag concurrently only one wins.
31+
//
32+
// This solution is based on a recomendation here:
33+
// https://developercommunity.visualstudio.com/content/problem/336946/class-with-constexpr-constructor-not-using-static.html?childToView=648454#comment-648454
34+
35+
namespace flags_internal {
36+
absl::Mutex* GetGlobalConstructionGuard();
37+
} // namespace flags_internal
38+
39+
// Public methods of `absl::Flag<T>` are NOT part of the Abseil Flags API.
40+
// See https://abseil.io/docs/cpp/guides/flags
41+
template <typename T>
42+
class Flag {
43+
public:
44+
// No constructor and destructor to ensure this is an aggregate type.
45+
// Visual Studio 2015 still requires the constructor for class to be
46+
// constexpr initializable.
47+
#if _MSC_VER <= 1900
48+
constexpr Flag(const char* name, const char* filename,
49+
const flags_internal::HelpGenFunc help_gen,
50+
const flags_internal::FlagDfltGenFunc default_value_gen)
51+
: name_(name),
52+
filename_(filename),
53+
help_gen_(help_gen),
54+
default_value_gen_(default_value_gen),
55+
inited_(false),
56+
impl_(nullptr) {}
57+
#endif
58+
59+
flags_internal::Flag<T>& GetImpl() const {
60+
if (!inited_.load(std::memory_order_acquire)) {
61+
absl::MutexLock l(flags_internal::GetGlobalConstructionGuard());
62+
63+
if (inited_.load(std::memory_order_acquire)) {
64+
return *impl_;
65+
}
66+
67+
impl_ = new flags_internal::Flag<T>(
68+
name_, filename_,
69+
{flags_internal::FlagHelpMsg(help_gen_),
70+
flags_internal::FlagHelpKind::kGenFunc},
71+
{flags_internal::FlagDefaultSrc(default_value_gen_),
72+
flags_internal::FlagDefaultKind::kGenFunc});
73+
inited_.store(true, std::memory_order_release);
74+
}
75+
76+
return *impl_;
77+
}
78+
79+
// Public methods of `absl::Flag<T>` are NOT part of the Abseil Flags API.
80+
// See https://abseil.io/docs/cpp/guides/flags
81+
bool IsRetired() const { return GetImpl().IsRetired(); }
82+
absl::string_view Name() const { return GetImpl().Name(); }
83+
std::string Help() const { return GetImpl().Help(); }
84+
bool IsModified() const { return GetImpl().IsModified(); }
85+
bool IsSpecifiedOnCommandLine() const {
86+
return GetImpl().IsSpecifiedOnCommandLine();
87+
}
88+
std::string Filename() const { return GetImpl().Filename(); }
89+
std::string DefaultValue() const { return GetImpl().DefaultValue(); }
90+
std::string CurrentValue() const { return GetImpl().CurrentValue(); }
91+
template <typename U>
92+
inline bool IsOfType() const {
93+
return GetImpl().template IsOfType<U>();
94+
}
95+
T Get() const {
96+
return flags_internal::FlagImplPeer::InvokeGet<T>(GetImpl());
97+
}
98+
void Set(const T& v) {
99+
flags_internal::FlagImplPeer::InvokeSet(GetImpl(), v);
100+
}
101+
void InvokeCallback() { GetImpl().InvokeCallback(); }
102+
103+
const CommandLineFlag& Reflect() const {
104+
return flags_internal::FlagImplPeer::InvokeReflect(GetImpl());
105+
}
106+
107+
// The data members are logically private, but they need to be public for
108+
// this to be an aggregate type.
109+
const char* name_;
110+
const char* filename_;
111+
const flags_internal::HelpGenFunc help_gen_;
112+
const flags_internal::FlagDfltGenFunc default_value_gen_;
113+
114+
mutable std::atomic<bool> inited_;
115+
mutable flags_internal::Flag<T>* impl_;
116+
};

absl/hash/internal/hash.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ namespace hash_internal {
2121
uint64_t MixingHashState::CombineLargeContiguousImpl32(
2222
uint64_t state, const unsigned char* first, size_t len) {
2323
while (len >= PiecewiseChunkSize()) {
24-
state =
25-
Mix(state, absl::hash_internal::CityHash32(reinterpret_cast<const char*>(first),
26-
PiecewiseChunkSize()));
24+
state = Mix(state,
25+
hash_internal::CityHash32(reinterpret_cast<const char*>(first),
26+
PiecewiseChunkSize()));
2727
len -= PiecewiseChunkSize();
2828
first += PiecewiseChunkSize();
2929
}

absl/hash/internal/hash.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@
4242
#include "absl/base/internal/unaligned_access.h"
4343
#include "absl/base/port.h"
4444
#include "absl/container/fixed_array.h"
45+
#include "absl/hash/internal/city.h"
4546
#include "absl/hash/internal/low_level_hash.h"
4647
#include "absl/meta/type_traits.h"
4748
#include "absl/numeric/int128.h"
4849
#include "absl/strings/string_view.h"
4950
#include "absl/types/optional.h"
5051
#include "absl/types/variant.h"
5152
#include "absl/utility/utility.h"
52-
#include "absl/hash/internal/city.h"
5353

5454
namespace absl {
5555
ABSL_NAMESPACE_BEGIN
@@ -883,7 +883,7 @@ class ABSL_DLL MixingHashState : public HashStateBase<MixingHashState> {
883883
#ifdef ABSL_HAVE_INTRINSIC_INT128
884884
return LowLevelHashImpl(data, len);
885885
#else
886-
return absl::hash_internal::CityHash64(reinterpret_cast<const char*>(data), len);
886+
return hash_internal::CityHash64(reinterpret_cast<const char*>(data), len);
887887
#endif
888888
}
889889

@@ -929,7 +929,7 @@ inline uint64_t MixingHashState::CombineContiguousImpl(
929929
if (ABSL_PREDICT_FALSE(len > PiecewiseChunkSize())) {
930930
return CombineLargeContiguousImpl32(state, first, len);
931931
}
932-
v = absl::hash_internal::CityHash32(reinterpret_cast<const char*>(first), len);
932+
v = hash_internal::CityHash32(reinterpret_cast<const char*>(first), len);
933933
} else if (len >= 4) {
934934
v = Read4To8(first, len);
935935
} else if (len > 0) {

absl/meta/type_traits.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,8 @@ using underlying_type_t = typename std::underlying_type<T>::type;
642642

643643
namespace type_traits_internal {
644644

645-
#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
645+
#if (defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703L) || \
646+
(defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
646647
// std::result_of is deprecated (C++17) or removed (C++20)
647648
template<typename> struct result_of;
648649
template<typename F, typename... Args>

0 commit comments

Comments
 (0)