From: Alex Rousskov Date: Sat, 12 Mar 2016 05:01:46 +0000 (-0700) Subject: Fixed clang -Winconsistent-missing-override warning. X-Git-Tag: SQUID_4_0_8~39 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1625e4a110c31424e55f023944a58072dd2aed4d;p=thirdparty%2Fsquid.git Fixed clang -Winconsistent-missing-override warning. AsyncJob classes can now use C++11 overrides as long as they use the new CBDATA_CHILD() macro instead of old CBDATA_CLASS(). I have prohibited multiple CBDATA_CHILD() classes on the same inheritance branch by adding the "final" specifier to toCbdata(). Such classes feel dangerous because they may have different sizes and it is not obvious to me whether the cbdata code will call the right size- specific delete for them. We can easily relax this later if needed. --- diff --git a/src/base/AsyncJob.h b/src/base/AsyncJob.h index b146c2fe66..aee8a999f7 100644 --- a/src/base/AsyncJob.h +++ b/src/base/AsyncJob.h @@ -11,6 +11,7 @@ #include "base/AsyncCall.h" #include "base/InstanceId.h" +#include "cbdata.h" template class CbcPointer; @@ -27,7 +28,7 @@ class CbcPointer; /// \ingroup AsyncJobAPI /// Base class for all asynchronous jobs -class AsyncJob +class AsyncJob: public CbdataParent { public: typedef CbcPointer Pointer; @@ -36,8 +37,6 @@ public: AsyncJob(const char *aTypeName); virtual ~AsyncJob(); - virtual void *toCbdata() = 0; - /// starts a freshly created job (i.e., makes the job asynchronous) static Pointer Start(AsyncJob *job); diff --git a/src/cbdata.h b/src/cbdata.h index 075167c284..5b815a82ad 100644 --- a/src/cbdata.h +++ b/src/cbdata.h @@ -272,11 +272,8 @@ int cbdataReferenceValid(const void *p); */ cbdata_type cbdataInternalAddType(cbdata_type type, const char *label, int size); -/** - * This needs to be defined FIRST in the class definition. - * It plays with private/public states in C++. - */ -#define CBDATA_CLASS(type) \ +/// declaration-generator used internally by CBDATA_CLASS() and CBDATA_CHILD() +#define CBDATA_DECL_(type, methodSpecifiers) \ public: \ void *operator new(size_t size) { \ assert(size == sizeof(type)); \ @@ -286,10 +283,29 @@ cbdata_type cbdataInternalAddType(cbdata_type type, const char *label, int size) void operator delete (void *address) { \ if (address) cbdataInternalFree(address,__FILE__,__LINE__); \ } \ - void *toCbdata() { return this; } \ + void *toCbdata() methodSpecifiers { return this; } \ private: \ static cbdata_type CBDATA_##type; +/// Starts cbdata-protection in a class hierarchy. +/// Child classes in the same hierarchy should use CBDATA_CHILD(). +class CbdataParent +{ +public: + virtual ~CbdataParent() = default; + virtual void *toCbdata() = 0; +}; + +/// cbdata-enables a stand-alone class that is not a CbdataParent child +/// sets the class declaration section to "private" +/// use this at the start of your class declaration for consistency sake +#define CBDATA_CLASS(type) CBDATA_DECL_(type, noexcept) + +/// cbdata-enables a CbdataParent child class (including grandchildren) +/// sets the class declaration section to "private" +/// use this at the start of your class declaration for consistency sake +#define CBDATA_CHILD(type) CBDATA_DECL_(type, override final) + /** * Creates a global instance pointer for the CBDATA memory allocator * to allocate and free objects for the matching CBDATA_CLASS(). diff --git a/src/fs/rock/RockHeaderUpdater.h b/src/fs/rock/RockHeaderUpdater.h index 704bb76c2b..10daf0b0d6 100644 --- a/src/fs/rock/RockHeaderUpdater.h +++ b/src/fs/rock/RockHeaderUpdater.h @@ -25,7 +25,7 @@ namespace Rock /// * chains the new entry prefix (1+ slots) to the old entry suffix (0+ slots) class HeaderUpdater: public AsyncJob { - CBDATA_CLASS(HeaderUpdater); + CBDATA_CHILD(HeaderUpdater); public: HeaderUpdater(const Rock::SwapDir::Pointer &aStore, const Ipc::StoreMapUpdate &update);