diff options
author | Derek Mauro <761129+derekmauro@users.noreply.github.com> | 2023-02-18 11:23:34 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-18 11:23:34 -0500 |
commit | c8a2f92586fe9b4e1aff049108f5db8064924d8e (patch) | |
tree | b09ad1431986a4dfe011567200ad7abbcef6e344 /absl/strings/internal/cord_internal.h | |
parent | 78be63686ba732b25052be15f8d6dee891c05749 (diff) | |
download | abseil-c8a2f92586fe9b4e1aff049108f5db8064924d8e.tar.gz abseil-c8a2f92586fe9b4e1aff049108f5db8064924d8e.tar.bz2 abseil-c8a2f92586fe9b4e1aff049108f5db8064924d8e.zip |
Make `SanitizerSafeCopy()` constexpr, and check for constant evaluation (#1399)
Also update test Docker container so that LTS patches can be tested
This patch cherry-picks 2 commits:
a0f9b465212aea24d3264b82d315b8ee59e8d7a0
35e8e3f7a2c6972d4c591448e8bbe4f9ed9f815a
Diffstat (limited to 'absl/strings/internal/cord_internal.h')
-rw-r--r-- | absl/strings/internal/cord_internal.h | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/absl/strings/internal/cord_internal.h b/absl/strings/internal/cord_internal.h index 63a81f4f..e6f0d544 100644 --- a/absl/strings/internal/cord_internal.h +++ b/absl/strings/internal/cord_internal.h @@ -768,18 +768,22 @@ class InlineData { } #ifdef ABSL_INTERNAL_CORD_HAVE_SANITIZER - Rep SanitizerSafeCopy() const { - Rep res; - if (is_tree()) { - res = *this; + constexpr Rep SanitizerSafeCopy() const { + if (!absl::is_constant_evaluated()) { + Rep res; + if (is_tree()) { + res = *this; + } else { + res.set_tag(tag()); + memcpy(res.as_chars(), as_chars(), inline_size()); + } + return res; } else { - res.set_tag(tag()); - memcpy(res.as_chars(), as_chars(), inline_size()); + return *this; } - return res; } #else - const Rep& SanitizerSafeCopy() const { return *this; } + constexpr const Rep& SanitizerSafeCopy() const { return *this; } #endif // If the data has length <= kMaxInline, we store it in `data`, and |