Commit 9cdb98e7 by Derek Mauro Committed by Copybara-Service

InlinedVector: Limit the scope of the maybe-uninitialized warning suppression

Due to changes in GCC 12, without this change, the warning fires

PiperOrigin-RevId: 453197246
Change-Id: I2e31cbff1707ab09868cf77dcf040b033984e654
parent 47345f63
...@@ -585,8 +585,20 @@ class InlinedVector { ...@@ -585,8 +585,20 @@ class InlinedVector {
if (ABSL_PREDICT_TRUE(n != 0)) { if (ABSL_PREDICT_TRUE(n != 0)) {
value_type dealias = v; value_type dealias = v;
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102329#c2
// It appears that GCC thinks that since `pos` is a const pointer and may
// point to uninitialized memory at this point, a warning should be
// issued. But `pos` is actually only used to compute an array index to
// write to.
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
return storage_.Insert(pos, CopyValueAdapter<A>(std::addressof(dealias)), return storage_.Insert(pos, CopyValueAdapter<A>(std::addressof(dealias)),
n); n);
#if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
} else { } else {
return const_cast<iterator>(pos); return const_cast<iterator>(pos);
} }
......
...@@ -40,7 +40,6 @@ namespace inlined_vector_internal { ...@@ -40,7 +40,6 @@ namespace inlined_vector_internal {
#if !defined(__clang__) && defined(__GNUC__) #if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds" #pragma GCC diagnostic ignored "-Warray-bounds"
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif #endif
template <typename A> template <typename A>
...@@ -942,7 +941,7 @@ auto Storage<T, N, A>::Swap(Storage* other_storage_ptr) -> void { ...@@ -942,7 +941,7 @@ auto Storage<T, N, A>::Swap(Storage* other_storage_ptr) -> void {
swap(GetAllocator(), other_storage_ptr->GetAllocator()); swap(GetAllocator(), other_storage_ptr->GetAllocator());
} }
// End ignore "array-bounds" and "maybe-uninitialized" // End ignore "array-bounds"
#if !defined(__clang__) && defined(__GNUC__) #if !defined(__clang__) && defined(__GNUC__)
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment