Skip to content

Commit b03438a

Browse files
asedenocopybara-github
authored andcommitted
Silence -Winvalid-offsetof for cel::common_internal::ReferenceCountedString
PiperOrigin-RevId: 688691954
1 parent accde9e commit b03438a

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

common/internal/reference_count.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ class ReferenceCountedStdString final : public ReferenceCounted {
6060
alignas(std::string) char string_[sizeof(std::string)];
6161
};
6262

63+
// ReferenceCountedString is non-standard-layout due to having virtual functions
64+
// from a base class. This causes compilers to warn about the use of offsetof(),
65+
// but it still works here, so silence the warning and proceed.
66+
#if defined(__GNUC__) || defined(__clang__)
67+
#pragma GCC diagnostic push
68+
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
69+
#endif
70+
6371
class ReferenceCountedString final : public ReferenceCounted {
6472
public:
6573
static const ReferenceCountedString* New(const char* data, size_t size) {
@@ -87,6 +95,10 @@ class ReferenceCountedString final : public ReferenceCounted {
8795
char data_[];
8896
};
8997

98+
#if defined(__GNUC__) || defined(__clang__)
99+
#pragma GCC diagnostic pop
100+
#endif
101+
90102
} // namespace
91103

92104
std::pair<absl::Nonnull<const ReferenceCount*>, absl::string_view>

0 commit comments

Comments
 (0)