mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 728512 - Make MOZ_ASSERT(cond, reason) work correctly on MSVC by hacking around a compiler bug. r=glandium
--HG-- extra : rebase_source : f955359300e02b27f0efda63bbb1983d85a56a5a
This commit is contained in:
parent
fa3512ba76
commit
87eee40a7e
@ -180,17 +180,29 @@ MOZ_Assert(const char* s, const char* file, int ln);
|
||||
# define MOZ_ASSERT_HELPER2(expr, explain) \
|
||||
((expr) ? ((void)0) : MOZ_Assert(#expr " (" explain ")", __FILE__, __LINE__))
|
||||
/* And now, helper macrology up the wazoo. */
|
||||
/* Count the number of arguments passed to MOZ_ASSERT. */
|
||||
# define MOZ_COUNT_ASSERT_ARGS(...) \
|
||||
MOZ_COUNT_ASSERT_ARGS_IMPL(__VA_ARGS__, 2, 1, 0)
|
||||
# define MOZ_COUNT_ASSERT_ARGS_IMPL(_1, _2, count, ...) \
|
||||
/*
|
||||
* Count the number of arguments passed to MOZ_ASSERT, very carefully
|
||||
* tiptoeing around an MSVC bug where it improperly expands __VA_ARGS__ as a
|
||||
* single token in argument lists. See these URLs for details:
|
||||
*
|
||||
* http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement
|
||||
* http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/#comment-644
|
||||
*/
|
||||
# define MOZ_COUNT_ASSERT_ARGS_IMPL2(_1, _2, count, ...) \
|
||||
count
|
||||
/* Invoke the right helper. */
|
||||
# define MOZ_ASSERT_VAHELP2(count, ...) MOZ_ASSERT_HELPER##count(__VA_ARGS__)
|
||||
# define MOZ_ASSERT_VAHELP(count, ...) MOZ_ASSERT_VAHELP2(count, __VA_ARGS__)
|
||||
# define MOZ_COUNT_ASSERT_ARGS_IMPL(args) \
|
||||
MOZ_COUNT_ASSERT_ARGS_IMPL2 args
|
||||
# define MOZ_COUNT_ASSERT_ARGS(...) \
|
||||
MOZ_COUNT_ASSERT_ARGS_IMPL((__VA_ARGS__, 2, 1, 0))
|
||||
/* Pick the right helper macro to invoke. */
|
||||
# define MOZ_ASSERT_CHOOSE_HELPER2(count) MOZ_ASSERT_HELPER##count
|
||||
# define MOZ_ASSERT_CHOOSE_HELPER1(count) MOZ_ASSERT_CHOOSE_HELPER2(count)
|
||||
# define MOZ_ASSERT_CHOOSE_HELPER(count) MOZ_ASSERT_CHOOSE_HELPER1(count)
|
||||
/* The actual macro. */
|
||||
# define MOZ_ASSERT_GLUE(x, y) x y
|
||||
# define MOZ_ASSERT(...) \
|
||||
MOZ_ASSERT_VAHELP(MOZ_COUNT_ASSERT_ARGS(__VA_ARGS__), __VA_ARGS__)
|
||||
MOZ_ASSERT_GLUE(MOZ_ASSERT_CHOOSE_HELPER(MOZ_COUNT_ASSERT_ARGS(__VA_ARGS__)), \
|
||||
(__VA_ARGS__))
|
||||
#else
|
||||
# define MOZ_ASSERT(...) ((void)0)
|
||||
#endif /* DEBUG */
|
||||
|
Loading…
Reference in New Issue
Block a user