]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fixed clang -Winconsistent-missing-override warning.
authorAlex Rousskov <rousskov@measurement-factory.com>
Sat, 12 Mar 2016 05:01:46 +0000 (22:01 -0700)
committerAlex Rousskov <rousskov@measurement-factory.com>
Sat, 12 Mar 2016 05:01:46 +0000 (22:01 -0700)
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.

src/base/AsyncJob.h
src/cbdata.h
src/fs/rock/RockHeaderUpdater.h

index b146c2fe66d1034eb0cc84bee70ef8c91ddd5107..aee8a999f7a6344efd6095898bf72a8429aab0ae 100644 (file)
@@ -11,6 +11,7 @@
 
 #include "base/AsyncCall.h"
 #include "base/InstanceId.h"
+#include "cbdata.h"
 
 template <class Cbc>
 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<AsyncJob> 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);
 
index 075167c284306954f34fa63d397c348ef82c05d7..5b815a82ad0d33dc8ac2ccef119a1135bf8738a9 100644 (file)
@@ -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().
index 704bb76c2bb57dfca1595b36e69643d975ef612a..10daf0b0d6e72536633a37211a11d7c27a7447e6 100644 (file)
@@ -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);