Closed Bug 839998 Opened 11 years ago Closed 11 years ago

Consider moving ALLOW_THIS_IN_INITIALIZER_LIST to MFBT

Categories

(Core :: MFBT, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla25

People

(Reporter: Ms2ger, Assigned: emk)

References

Details

Attachments

(2 files, 1 obsolete file)

This macro comes from the chromium code, but has recently started being used in netwerk too. Maybe this is a better solution than the thisInInitializer() functions we've been using elsewhere.
wdyt?
Flags: needinfo?(jwalden+bmo)
Blocks: 859022
Interesting; I hadn't seen this before now.  Seems slightly clearer about the purpose than thisDuringConstruction() or whatever, or at least there's a breadcrumb trail to follow to see the why of it, so sounds fine to me.

MOZ_ALLOW_THIS_IN_INITIALIZER_LIST is a bit long, but it *is* pretty clear.  Suggestions for shorter names appreciated.
Flags: needinfo?(jwalden+bmo)
Unlike chromium's counterpart, this macro has no parameters because the only possible parameter value is "this".
I removed "ALLOW" from the name because the macro itself represents "this".
Assignee: nobody → VYV03354
Status: NEW → ASSIGNED
Attachment #766690 - Flags: review?(jwalden+bmo)
Comment on attachment 766690 [details] [diff] [review]
Introduce MOZ_THIS_IN_INITIALIZER_LIST macro

Review of attachment 766690 [details] [diff] [review]:
-----------------------------------------------------------------

It'd be good if you fixed up a bunch of existing thisDuringConstruction users to use this, to set a precedent when it lands.

::: mfbt/Attributes.h
@@ +405,5 @@
>  #endif /* MOZ_CLANG_PLUGIN */
>  
> +/*
> + * MOZ_THIS_IN_INITIALIZER_LIST is used to avoid a warning when we know that
> + * it's safe to use 'this' in an initializer list.

Ms2ger and I think this should be a macro function, so that parentheses are required after it.  I'm not quite sure why I think this way, it's mostly an inchoate intuition.  Maybe something about how I might expect an identifier to not have different meanings in different contexts (and obviously |this| differs per class)?  I dunno.  Anyway, smack some parens after this, please.

@@ +408,5 @@
> + * MOZ_THIS_IN_INITIALIZER_LIST is used to avoid a warning when we know that
> + * it's safe to use 'this' in an initializer list.
> + */
> +#ifdef _MSC_VER
> +#define MOZ_THIS_IN_INITIALIZER_LIST \

Indentation nits:

#ifdef _MSC_VER
#  define MOZ... \
     __pragma(...) \
     __pragma(...) \
     this \
     __pragma(...)
#else
#  define ...
#endif
Attachment #766690 - Flags: review?(jwalden+bmo) → review+
patch for checkin
Attachment #766690 - Attachment is obsolete: true
Attachment #767294 - Flags: review+
Comment on attachment 767297 [details] [diff] [review]
Bug 839998 - Replace thisDuringConstruction() with MOZ_THIS_IN_INITIALIZER_LIST()

Review of attachment 767297 [details] [diff] [review]:
-----------------------------------------------------------------

Just throwing it out there: one nice feature of the Google macro was that you still saw |this| as an identifier in the source, which could be helpful when editing the declaration/definition of particularly large classes, and wanting to know if any part of the constructor uses |this| prematurely.  Might MOZ_IN_INITIALIZER_LIST(this) possibly be better along these lines?  Again, just throwing it out there, not asking for a redo of anything.
Attachment #767297 - Flags: review?(jwalden+bmo) → review+
https://hg.mozilla.org/mozilla-central/rev/6afe0a48ad5e
https://hg.mozilla.org/mozilla-central/rev/d19ecc13f95a
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla25
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: