Commit 1c233c55 by Adam Gajda Committed by Copybara-Service

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 d8027081

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
parent 2a7d0da1
...@@ -44,6 +44,7 @@ list(APPEND ABSL_GCC_FLAGS ...@@ -44,6 +44,7 @@ list(APPEND ABSL_GCC_FLAGS
"-Wconversion-null" "-Wconversion-null"
"-Wformat-security" "-Wformat-security"
"-Wmissing-declarations" "-Wmissing-declarations"
"-Wnon-virtual-dtor"
"-Woverlength-strings" "-Woverlength-strings"
"-Wpointer-arith" "-Wpointer-arith"
"-Wundef" "-Wundef"
...@@ -61,6 +62,7 @@ list(APPEND ABSL_GCC_TEST_FLAGS ...@@ -61,6 +62,7 @@ list(APPEND ABSL_GCC_TEST_FLAGS
"-Wcast-qual" "-Wcast-qual"
"-Wconversion-null" "-Wconversion-null"
"-Wformat-security" "-Wformat-security"
"-Wnon-virtual-dtor"
"-Woverlength-strings" "-Woverlength-strings"
"-Wpointer-arith" "-Wpointer-arith"
"-Wundef" "-Wundef"
......
...@@ -45,6 +45,7 @@ ABSL_GCC_FLAGS = [ ...@@ -45,6 +45,7 @@ ABSL_GCC_FLAGS = [
"-Wconversion-null", "-Wconversion-null",
"-Wformat-security", "-Wformat-security",
"-Wmissing-declarations", "-Wmissing-declarations",
"-Wnon-virtual-dtor",
"-Woverlength-strings", "-Woverlength-strings",
"-Wpointer-arith", "-Wpointer-arith",
"-Wundef", "-Wundef",
...@@ -62,6 +63,7 @@ ABSL_GCC_TEST_FLAGS = [ ...@@ -62,6 +63,7 @@ ABSL_GCC_TEST_FLAGS = [
"-Wcast-qual", "-Wcast-qual",
"-Wconversion-null", "-Wconversion-null",
"-Wformat-security", "-Wformat-security",
"-Wnon-virtual-dtor",
"-Woverlength-strings", "-Woverlength-strings",
"-Wpointer-arith", "-Wpointer-arith",
"-Wundef", "-Wundef",
......
...@@ -18,6 +18,7 @@ ABSL_GCC_FLAGS = [ ...@@ -18,6 +18,7 @@ ABSL_GCC_FLAGS = [
"-Wconversion-null", "-Wconversion-null",
"-Wformat-security", "-Wformat-security",
"-Wmissing-declarations", "-Wmissing-declarations",
"-Wnon-virtual-dtor",
"-Woverlength-strings", "-Woverlength-strings",
"-Wpointer-arith", "-Wpointer-arith",
"-Wundef", "-Wundef",
......
...@@ -59,6 +59,14 @@ class PrivateHandleAccessor; ...@@ -59,6 +59,14 @@ class PrivateHandleAccessor;
// // Now you can get flag info from that reflection handle. // // Now you can get flag info from that reflection handle.
// std::string flag_location = my_flag_data->Filename(); // std::string flag_location = my_flag_data->Filename();
// ... // ...
// 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 CommandLineFlag { class CommandLineFlag {
public: public:
constexpr CommandLineFlag() = default; constexpr CommandLineFlag() = default;
...@@ -193,6 +201,9 @@ class CommandLineFlag { ...@@ -193,6 +201,9 @@ class CommandLineFlag {
// flag's value type. // flag's value type.
virtual void CheckDefaultValueParsingRoundtrip() const = 0; virtual void CheckDefaultValueParsingRoundtrip() const = 0;
}; };
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // namespace absl
......
...@@ -424,6 +424,13 @@ struct DynValueDeleter { ...@@ -424,6 +424,13 @@ struct DynValueDeleter {
class FlagState; 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 { class FlagImpl final : public CommandLineFlag {
public: public:
constexpr FlagImpl(const char* name, const char* filename, FlagOpFn op, constexpr FlagImpl(const char* name, const char* filename, FlagOpFn op,
...@@ -623,6 +630,9 @@ class FlagImpl final : public CommandLineFlag { ...@@ -623,6 +630,9 @@ class FlagImpl final : public CommandLineFlag {
// problems. // problems.
alignas(absl::Mutex) mutable char data_guard_[sizeof(absl::Mutex)]; 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 // 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) { ...@@ -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 // Round sizeof(FlagImp) to a multiple of alignof(FlagValue<T>) to get the
// offset of the data. // offset of the data.
size_t round_to = alignof(FlagValue<T>); size_t round_to = alignof(FlagValue<T>);
size_t offset = size_t offset = (sizeof(FlagImpl) + round_to - 1) / round_to * round_to;
(sizeof(FlagImpl) + round_to - 1) / round_to * round_to;
return reinterpret_cast<void*>(offset); return reinterpret_cast<void*>(offset);
} }
} }
......
...@@ -217,6 +217,13 @@ void FinalizeRegistry() { ...@@ -217,6 +217,13 @@ void FinalizeRegistry() {
namespace { namespace {
// 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 RetiredFlagObj final : public CommandLineFlag { class RetiredFlagObj final : public CommandLineFlag {
public: public:
constexpr RetiredFlagObj(const char* name, FlagFastTypeId type_id) constexpr RetiredFlagObj(const char* name, FlagFastTypeId type_id)
...@@ -276,6 +283,9 @@ class RetiredFlagObj final : public CommandLineFlag { ...@@ -276,6 +283,9 @@ class RetiredFlagObj final : public CommandLineFlag {
const char* const name_; const char* const name_;
const FlagFastTypeId type_id_; const FlagFastTypeId type_id_;
}; };
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
} // namespace } // namespace
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment