Work around MSVC compiler bug to make new (fallible_t()) work




7 years ago
4 years ago


(Reporter: Joe Drew (not getting mail), Unassigned)


Windows 8.1

Firefox Tracking Flags

(Not tracked)




7 years ago
Related: bug 613766, bug 613697.

We should look in to instantiating a global mozilla::fallible_t to make new (fallible) possible. Chris Jones tells me that we were worried about linker overhead and therefore didn't do this, but using fallible new (rather than ugly fallible malloc) is important enough that we should have a very good (measured) reason to not use it.
The model was originally going to be std::nothrow.  I'm skeptical that adding two more globally exported symbols to libmozalloc (mozilla::fallible and mozilla::infallible) is going to noticeably affect link times, and now that we're working around the MSVC bug in several places, it's worth reopening that discussion IMHO.
This still doesn't work with MSVC 2013.
OS: Mac OS X → Windows 8.1
More directly, we should either make this work or remove support for it. I don't imagine it's useful to have this only work on non-Windows. Since we need to support non-Windows, I basically need to use moz_malloc.

Comment 4

4 years ago
I don't quite understand what this bug is about. Bug 679503 is resolved as WORKSFORME, and we do have instances in the tree of new ((fallible_t())) e.g. in nsZipArchive.cpp. What's the problem we're trying to solve-or-remove here?


4 years ago
Flags: needinfo?(jgilbert)
uint8_t* foo = new (fallible_t()) uint8_t[4];
This doesn't compile on MSVC2013.

I get this:> error C2066: cast to function type is illegal
> error C2440: 'initializing' : cannot convert from 'mozilla::fallible_t (__cdecl **)(void)' to 'uint8_t *'
>         Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
> error C2144: syntax error : 'uint8_t' should be preceded by ';'
> warning C4091: '' : ignored on left of 'unsigned char' when no variable is declared
> error C2143: syntax error : missing ';' before '['
> error C3409: empty attribute block is not allowed
> error C2143: syntax error : missing ']' before 'constant'
> error C2143: syntax error : missing ';' before 'constant'
> error C2143: syntax error : missing ';' before ']'
Flags: needinfo?(jgilbert)

Comment 6

4 years ago
I don't understand why that is, but it does work with the extra set of parens:

uint8_t* foo = new ((fallible_t())) uint8_t[4];

I think we should just use that.
Sounds good to me. I can confirm that an extra set of parens makes it work for me.


4 years ago
Last Resolved: 4 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.