summaryrefslogtreecommitdiff
path: root/absl/flags/internal/flag.h
diff options
context:
space:
mode:
authorGravatar Adam Gajda <80600850+adgajda@users.noreply.github.com>2024-03-13 13:19:59 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2024-03-13 13:20:57 -0700
commit1c233c55171af9101962ba9a5c2bda7ace18fcfe (patch)
tree205d09abada48e61a96071c870037aa64cc0b310 /absl/flags/internal/flag.h
parent2a7d0da1dd6ab149eaa66b5582f0a21a0abc2df4 (diff)
PR #1603: Disable -Wnon-virtual-dtor warning for CommandLineFlag implementations
Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1603 Merge e324303b1f2aaee8e4418cffb838f150a2d4f4e7 into d802708117c6ef6b9783efe499b2a2d0d0536c77 Merging this change closes #1603 COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1603 from adgajda:master e324303b1f2aaee8e4418cffb838f150a2d4f4e7 PiperOrigin-RevId: 615522811 Change-Id: I46a388ac62ffd42ce175dbfa04e414dd498855f8
Diffstat (limited to 'absl/flags/internal/flag.h')
-rw-r--r--absl/flags/internal/flag.h13
1 files changed, 11 insertions, 2 deletions
diff --git a/absl/flags/internal/flag.h b/absl/flags/internal/flag.h
index 7b056382..602531b1 100644
--- a/absl/flags/internal/flag.h
+++ b/absl/flags/internal/flag.h
@@ -424,6 +424,13 @@ struct DynValueDeleter {
class FlagState;
+// These are only used as constexpr global objects.
+// They do not use a virtual destructor to simplify their implementation.
+// They are not destroyed except at program exit, so leaks do not matter.
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
+#endif
class FlagImpl final : public CommandLineFlag {
public:
constexpr FlagImpl(const char* name, const char* filename, FlagOpFn op,
@@ -623,6 +630,9 @@ class FlagImpl final : public CommandLineFlag {
// problems.
alignas(absl::Mutex) mutable char data_guard_[sizeof(absl::Mutex)];
};
+#if defined(__GNUC__) && !defined(__clang__)
+#pragma GCC diagnostic pop
+#endif
///////////////////////////////////////////////////////////////////////////////
// The Flag object parameterized by the flag's value type. This class implements
@@ -753,8 +763,7 @@ void* FlagOps(FlagOp op, const void* v1, void* v2, void* v3) {
// Round sizeof(FlagImp) to a multiple of alignof(FlagValue<T>) to get the
// offset of the data.
size_t round_to = alignof(FlagValue<T>);
- size_t offset =
- (sizeof(FlagImpl) + round_to - 1) / round_to * round_to;
+ size_t offset = (sizeof(FlagImpl) + round_to - 1) / round_to * round_to;
return reinterpret_cast<void*>(offset);
}
}