Closed Bug 728512 Opened 8 years ago Closed 8 years ago

MOZ_ASSERT(cond, "message") doesn't work on MSVC due to a compiler bug

Categories

(Core :: MFBT, defect, major)

All
Windows 7
defect
Not set
major

Tracking

()

RESOLVED FIXED
mozilla13

People

(Reporter: Waldo, Assigned: Waldo)

Details

Attachments

(1 file, 1 obsolete file)

Attached patch PatchSplinter Review
It turns out the two-argument form of the MOZ_ASSERT macro improperly expands on MSVC, with the result that MOZ_ASSERT(false, "!!!") won't trigger.  That's really not good.

Basically it seems MSVC treats __VA_ARGS__ as a single token when expanding it in macro argument lists, rather than as a variadic number of tokens.  Here's the bug report:

http://connect.microsoft.com/VisualStudio/feedback/details/380090/variadic-macro-replacement

This comment suggests the glimmer of a workaround.

http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/

The way we use count arguments gets used a bit more trickily than there, tho, so the ultimate fix is not quite as simple as that.

I've tested this on MSVC, gcc (including on the demented version on OS X), and clang.  According to the .i files that get generated for the two-argument form, this should work correctly everywhere.
Attachment #598475 - Flags: review?(mh+mozilla)
Attachment #598475 - Flags: review?(mh+mozilla) → review+
https://hg.mozilla.org/mozilla-central/rev/163fa5650f57
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Comment on attachment 653136 [details] [diff] [review]
and 733002: add support for labels to DataChannels

Uploaded to wrong bug, sorry
Attachment #653136 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.