Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Silence -Winvalid-offsetof for cel::common_internal::ReferenceCountedString #1006

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions common/internal/reference_count.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ class ReferenceCountedStdString final : public ReferenceCounted {
alignas(std::string) char string_[sizeof(std::string)];
};

// ReferenceCountedString is non-standard-layout due to having virtual functions
// from a base class. This causes compilers to warn about the use of offsetof(),
// but it still works here, so silence the warning and proceed.
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
#endif

class ReferenceCountedString final : public ReferenceCounted {
public:
static const ReferenceCountedString* New(const char* data, size_t size) {
Expand Down Expand Up @@ -87,6 +95,10 @@ class ReferenceCountedString final : public ReferenceCounted {
char data_[];
};

#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif

} // namespace

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