Last Comment Bug 733708 - gfx/layers fail to compile on mingw
: gfx/layers fail to compile on mingw
Product: Core
Classification: Components
Component: Graphics (show other bugs)
: Trunk
: x86 Windows 7
-- normal (vote)
: mozilla15
Assigned To: Jacek Caban
: Milan Sreckovic [:milan]
Depends on:
  Show dependency treegraph
Reported: 2012-03-07 02:57 PST by Jacek Caban
Modified: 2012-05-23 08:06 PDT (History)
2 users (show)
See Also:
Crash Signature:
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---

fix v1.0 (3.55 KB, patch)
2012-03-07 02:57 PST, Jacek Caban
no flags Details | Diff | Splinter Review
fix (3.53 KB, patch)
2012-05-18 06:05 PDT, Jacek Caban
bas: review+
Details | Diff | Splinter Review

Description User image Jacek Caban 2012-03-07 02:57:34 PST
Created attachment 603653 [details] [diff] [review]
fix v1.0

I agree that initialization by assignment looks nicer, but it's not really the same thing in standard C++
Comment 1 User image Ali Juma [:ajuma] 2012-03-07 06:26:04 PST
Comment on attachment 603653 [details] [diff] [review]
fix v1.0

Flagging Bas for review since he wrote that code.
Comment 2 User image Jacek Caban 2012-03-07 06:28:03 PST
Oh, thanks, I was sure I've set it during filling the bug.
Comment 3 User image Jacek Caban 2012-05-18 06:03:54 PDT
Comment on attachment 603653 [details] [diff] [review]
fix v1.0

Bas, I saw that you fixed this while working on that code. Thanks for that. Sadly, as part of bug 716439, another change that broke compilation in the same way landed. I will reuse this bug for the new patch.

I've investigated the situation again to see if I can find solution to prevent future breakages. Unfortunately, the answer is no, but let me explain it here for the reference.

The problem is that in statements like this:

nsAutoPtr<ClassName> x = new ClassName();

it's not an usual assignment, it is an initializing assignment. Such assignment, according to the standard, can't have an implicit cast, such as ClassName* -> nsAutoPtr is. That's what GCC complains about in this code. MSVC treats it like two separated statements:

nsAutoPtr<ClassName> x; x = ClassName();

Thus it uses default constructor for initialization and then operator= for the assignment. This difference is not specific to mingw. The same applies to all GCCs. I'm sure it causes occasional problems with all code shared between platforms, but they are caught by Tinderbox. So having more uniform behavior would be desirable. Two solutions I've considered are:

1) Make GCC accept non-standard syntax
I couldn't find a way to make it work.

2) Make MSVC *not* accept this syntax
If we could disable this, that would do the trick. I'm not aware of anything we could put into nsAutoPtr that would prohibit such syntax. It's possible to disable *all* MSVC C++ extensions by a compiler switch:

but it's not possible to do it per-feature. It solvers this particular problem, but the switch either all or nothing. And "all" isn't an option - even Microsoft's own platform headers fail to compile with this option.

So... there is no other way than fixing this stuff manually once it shows up.
Comment 4 User image Jacek Caban 2012-05-18 06:05:00 PDT
Created attachment 625080 [details] [diff] [review]
Comment 5 User image Jacek Caban 2012-05-22 01:45:21 PDT
Thanks for review.
Comment 6 User image Ed Morley [:emorley] 2012-05-23 08:06:03 PDT

Note You need to log in before you can comment on or make changes to this bug.