Bug 1369622 - Restore static asserts for lack of arguments on some macros. r?froydnj draft
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 02 Jun 2017 15:07:58 +0900
changeset 588096 dbf0550621ba1346d6fe2332c54104fb9912fe81
parent 588095 6947d24ec141c30cdc59ac98f1a6535b58853b01
child 588097 3cd7508fbf53d1be94174a9a795378acd0556110
push id61910
push userbmo:mh+mozilla@glandium.org
push dateFri, 02 Jun 2017 06:13:28 +0000
reviewersfroydnj
bugs1369622, 1368932
milestone55.0a1
Bug 1369622 - Restore static asserts for lack of arguments on some macros. r?froydnj Bug 1368932 removed MOZ_STATIC_ASSERT_VALID_ARG_COUNT because it didn't actually work for large numbers of arguments. But it was kind of useful for macros that expand to something broken when they are given no variadic argument at all. Now that we have a macro that doesn't require tricks to count empty arguments lists, however, we can use straightforward static_asserts instead of a generic macro, which has the side effect of providing more context in the error message.
xpcom/base/nsIClassInfoImpl.h
xpcom/base/nsISupportsImpl.h
--- a/xpcom/base/nsIClassInfoImpl.h
+++ b/xpcom/base/nsIClassInfoImpl.h
@@ -151,21 +151,25 @@ NS_CI_INTERFACE_GETTER_NAME(_class)(uint
                                             sizeof(nsIID));
 
 #define NS_CLASSINFO_HELPER_END                                               \
     MOZ_ASSERT(i == *count, "Incorrent number of entries");                   \
     return NS_OK;                                                             \
 }
 
 #define NS_IMPL_CI_INTERFACE_GETTER(aClass, ...)                              \
+  static_assert(MOZ_ARG_COUNT(__VA_ARGS__) > 0,                               \
+                "Need more arguments to NS_IMPL_CI_INTERFACE_GETTER");        \
   NS_CLASSINFO_HELPER_BEGIN(aClass, MOZ_ARG_COUNT(__VA_ARGS__))               \
     MOZ_FOR_EACH(NS_CLASSINFO_HELPER_ENTRY, (), (__VA_ARGS__))                \
   NS_CLASSINFO_HELPER_END
 
 #define NS_IMPL_QUERY_INTERFACE_CI(aClass, ...)                               \
+  static_assert(MOZ_ARG_COUNT(__VA_ARGS__) > 0,                               \
+                "Need more arguments to NS_IMPL_QUERY_INTERFACE_CI");         \
   NS_INTERFACE_MAP_BEGIN(aClass)                                              \
     MOZ_FOR_EACH(NS_INTERFACE_MAP_ENTRY, (), (__VA_ARGS__))                   \
     NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, MOZ_ARG_1(__VA_ARGS__))     \
     NS_IMPL_QUERY_CLASSINFO(aClass)                                           \
   NS_INTERFACE_MAP_END
 
 #define NS_IMPL_ISUPPORTS_CI(aClass, ...)                                     \
   NS_IMPL_ADDREF(aClass)                                                      \
--- a/xpcom/base/nsISupportsImpl.h
+++ b/xpcom/base/nsISupportsImpl.h
@@ -955,16 +955,18 @@ NS_IMETHODIMP _class::QueryInterface(REF
   NS_IMPL_QUERY_TAIL_USING_AGGREGATOR(_aggregator)
 
 #define NS_INTERFACE_TABLE0(_class)                                           \
   NS_INTERFACE_TABLE_BEGIN                                                    \
     NS_INTERFACE_TABLE_ENTRY(_class, nsISupports)                             \
   NS_INTERFACE_TABLE_END
 
 #define NS_INTERFACE_TABLE(aClass, ...)                                       \
+  static_assert(MOZ_ARG_COUNT(__VA_ARGS__) > 0,                               \
+                "Need more arguments to NS_INTERFACE_TABLE");                 \
   NS_INTERFACE_TABLE_BEGIN                                                    \
     MOZ_FOR_EACH(NS_INTERFACE_TABLE_ENTRY, (aClass,), (__VA_ARGS__))          \
     NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(aClass, nsISupports,                   \
                                        MOZ_ARG_1(__VA_ARGS__))                \
   NS_INTERFACE_TABLE_END
 
 #define NS_IMPL_QUERY_INTERFACE0(_class)                                      \
   NS_INTERFACE_TABLE_HEAD(_class)                                             \
@@ -1035,16 +1037,18 @@ NS_IMETHODIMP_(MozExternalRefCountType) 
 NS_IMETHODIMP_(MozExternalRefCountType) Class::Release(void)                  \
 {                                                                             \
   return Super::Release();                                                    \
 }
 
 #define NS_INTERFACE_TABLE_INHERITED0(Class) /* Nothing to do here */
 
 #define NS_INTERFACE_TABLE_INHERITED(aClass, ...)                             \
+  static_assert(MOZ_ARG_COUNT(__VA_ARGS__) > 0,                               \
+                "Need more arguments to NS_INTERFACE_TABLE_INHERITED");       \
   NS_INTERFACE_TABLE_BEGIN                                                    \
     MOZ_FOR_EACH(NS_INTERFACE_TABLE_ENTRY, (aClass,), (__VA_ARGS__))          \
   NS_INTERFACE_TABLE_END
 
 #define NS_IMPL_QUERY_INTERFACE_INHERITED(aClass, aSuper, ...)                \
   NS_INTERFACE_TABLE_HEAD(aClass)                                             \
   NS_INTERFACE_TABLE_INHERITED(aClass, __VA_ARGS__)                           \
   NS_INTERFACE_TABLE_TAIL_INHERITING(aSuper)