Browse Source

Require semicolon after saveload macroses

bulatman 1 year ago
parent
commit
df6af3ee47

+ 1 - 1
library/cpp/accurate_accumulate/accurate_accumulate.h

@@ -83,7 +83,7 @@ public:
         return *this = TValueType(*this) / TValueType(x);
     }
 
-    Y_SAVELOAD_DEFINE(Sum_, Compensation_)
+    Y_SAVELOAD_DEFINE(Sum_, Compensation_);
 
 private:
     TValueType Sum_;

+ 5 - 4
library/cpp/binsaver/bin_saver.h

@@ -14,6 +14,7 @@
 #include <util/generic/ylimits.h>
 #include <util/memory/blob.h>
 #include <util/digest/murmur.h>
+#include <util/system/compiler.h>
 
 #include <array>
 #include <bitset>
@@ -623,24 +624,24 @@ struct TRegisterSaveLoadType {
     int operator&(IBinSaver& f) { \
         f.AddMulti(__VA_ARGS__);  \
         return 0;                 \
-    }
+    } Y_SEMICOLON_GUARD
 
 #define SAVELOAD_OVERRIDE_WITHOUT_BASE(...) \
     int operator&(IBinSaver& f) override {  \
         f.AddMulti(__VA_ARGS__);            \
         return 0;                           \
-    }
+    } Y_SEMICOLON_GUARD
 
 #define SAVELOAD_OVERRIDE(base, ...)       \
     int operator&(IBinSaver& f) override { \
         base::operator&(f);                \
         f.AddMulti(__VA_ARGS__);           \
         return 0;                          \
-    }
+    } Y_SEMICOLON_GUARD
 
 #define SAVELOAD_BASE(...)        \
     int operator&(IBinSaver& f) { \
         TBase::operator&(f);      \
         f.AddMulti(__VA_ARGS__);  \
         return 0;                 \
-    }
+    } Y_SEMICOLON_GUARD

+ 2 - 2
library/cpp/netliba/v6/ib_collective.h

@@ -6,7 +6,7 @@ namespace NNetliba {
     struct TCollectiveInit {
         int Size, Rank;
 
-        SAVELOAD(Size, Rank)
+        SAVELOAD(Size, Rank);
     };
 
     struct TCollectiveLinkSet {
@@ -17,7 +17,7 @@ namespace NNetliba {
         TVector<TVector<int>> HostGroup; // HostGroup[0] - switchId, HostGroup[1] - hostId within the switch
         TVector<TLinkInfo> Links;
 
-        SAVELOAD(Hosts, HostGroup, Links)
+        SAVELOAD(Hosts, HostGroup, Links);
     };
 
     struct IAllDataSync: public TThrRefBase {

+ 4 - 0
util/system/compiler.h

@@ -613,6 +613,10 @@ _YandexAbort();
     #define Y_REINITIALIZES_OBJECT
 #endif
 
+// Use at the end of macros declaration. It allows macros usage only with semicolon at the end.
+// It prevents from warnings for extra semicolons when building with flag `-Wextra-semi`.
+#define Y_SEMICOLON_GUARD static_assert(true, "")
+
 #ifdef __cplusplus
 
 void UseCharPointerImpl(volatile const char*);

+ 4 - 1
util/ysafeptr.h

@@ -1,6 +1,7 @@
 #pragma once
 
 #include <stddef.h>
+#include <util/system/compiler.h>
 #include <util/system/yassert.h>
 #include <util/system/defaults.h>
 #include <util/system/tls.h>
@@ -209,7 +210,9 @@ protected:                                                        \
         this->ObjData += nHoldObjs;                               \
     }                                                             \
                                                                   \
-private:
+private:                                                          \
+    Y_SEMICOLON_GUARD
+
 #define OBJECT_NOCOPY_METHODS(classname) OBJECT_METHODS(classname)
 #define BASIC_REGISTER_CLASS(classname)                                              \
     Y_PRAGMA_DIAGNOSTIC_PUSH                                                         \

+ 5 - 2
util/ysaveload.h

@@ -8,6 +8,7 @@
 #include <util/generic/algorithm.h>
 #include <util/stream/output.h>
 #include <util/stream/input.h>
+#include <util/system/compiler.h>
 
 #ifndef __NVCC__
     // cuda is compiled in C++14 mode at the time
@@ -710,7 +711,8 @@ static inline void LoadMany(S* s, Ts&... t) {
                                                \
     inline void Load(IInputStream* s) {        \
         ::LoadMany(s, __VA_ARGS__);            \
-    }
+    }                                          \
+    Y_SEMICOLON_GUARD
 
 #define Y_SAVELOAD_DEFINE_OVERRIDE(...)          \
     void Save(IOutputStream* s) const override { \
@@ -719,7 +721,8 @@ static inline void LoadMany(S* s, Ts&... t) {
                                                  \
     void Load(IInputStream* s) override {        \
         ::LoadMany(s, __VA_ARGS__);              \
-    }
+    }                                            \
+    Y_SEMICOLON_GUARD
 
 template <class T>
 struct TNonVirtualSaver {

+ 1 - 1
util/ysaveload_ut.cpp

@@ -57,7 +57,7 @@ class TSaveLoadTest: public TTestBase {
         TString Str;
         ui32 Int;
 
-        Y_SAVELOAD_DEFINE(Str, Int)
+        Y_SAVELOAD_DEFINE(Str, Int);
     };
 
 private: