Skip to content

Commit

Permalink
suppress -Warray-bounds in bdlc_indexclerk (DRQS 176376910) (#4907)
Browse files Browse the repository at this point in the history
* suppress -Warray-bounds in bdlc_indexclerk

* add missing include
  • Loading branch information
t3nsor authored and GitHub Enterprise committed Aug 21, 2024
1 parent 87696e5 commit 0c2b22b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions groups/bdl/bdlc/bdlc_indexclerk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ BSLS_IDENT_RCSID(bdlc_indexclerk_cpp,"$Id$ $CSID$")
#include <bsl_ostream.h>
#include <bsl_vector.h>

///Implementation Notes
///--------------------
// When 'BSLS_ASSERT' is enabled and 'IndexClerkIter::operator*' is inlined,
// GCC 12 to 14 (the latest version at the time of writing) can sometimes
// optimize the code into a form that duplicates the access to 'd_index_p' in
// the branch where '0 == d_index_p.base()', which triggers '-Warray-bounds'
// (GCC bug 108770). The ideal solution is to replace 'BSLS_ASSERT' with a
// variant that is statically known to never continue on failure, but such a
// facility doesn't currently exist in BDE, so instead we must manually disable
// the warning in the body of 'operator*'.

namespace BloombergLP {
namespace bdlc {

Expand Down
11 changes: 11 additions & 0 deletions groups/bdl/bdlc/bdlc_indexclerk.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ BSLS_IDENT("$Id: $")
#include <bslmf_nestedtraitdeclaration.h>

#include <bsls_assert.h>
#include <bsls_platform.h>
#include <bsls_review.h>

#include <bsl_iosfwd.h>
Expand Down Expand Up @@ -456,9 +457,19 @@ IndexClerkIter& IndexClerkIter::operator--()
inline
int IndexClerkIter::operator*() const
{
#if defined(BSLS_PLATFORM_CMP_GNU) && \
BSLS_PLATFORM_CMP_VERSION >= 120000 && BSLS_PLATFORM_CMP_VERSION < 150000
// See implementation notes in the .cpp file for explanation.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
#endif
BSLS_ASSERT(0 != d_index_p.base());

return *d_index_p;
#if defined(BSLS_PLATFORM_CMP_GNU) && \
BSLS_PLATFORM_CMP_VERSION >= 120000 && BSLS_PLATFORM_CMP_VERSION < 150000
#pragma GCC diagnostic pop
#endif
}

} // close package namespace
Expand Down

0 comments on commit 0c2b22b

Please sign in to comment.