The following classes are designed to cause assertions to detect inadvertent use of guard objects as temporaries.
In other words, when we have a guard object whose only purpose is its constructor and destructor (and is never otherwise referenced), the intended use might be: AutoRestore savePainting(mIsPainting); but is is easy to accidentally write: AutoRestore(mIsPainting); which compiles just fine, but runs the destructor well before the intended time.
They work by adding (ifdef DEBUG) an additional parameter to the guard object's constructor, with a default value, so that users of the guard object's API do not need to do anything. The default value of this parameter is a temporary object. C++ (ISO/IEC 14882:1998), section 12.2 [class.temporary], clauses 4 and 5 seem to assume a guarantee that temporaries are destroyed in the reverse of their construction order, but I actually can't find a statement that that is true in the general case (beyond the two specific cases mentioned there). However, it seems to be true.
These classes are intended to be used only via the macros immediately below them: MOZILLA_DECL_USE_GUARD_OBJECT_NOTIFIER declares (ifdef DEBUG) a member variable, and should be put where a declaration of a private member variable would be placed. MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM should be placed at the end of the parameters to each constructor of the guard object; it declares (ifdef DEBUG) an additional parameter. (But use the *_ONLY_PARAM variant for constructors that take no other parameters.) MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL should likewise be used in the implementation of such constructors when they are not inline. MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT should be used in the implementation of such constructors to pass the parameter to a base class that also uses these macros MOZILLA_GUARD_OBJECT_NOTIFIER_INIT is a statement that belongs in each constructor. It uses the parameter declared by MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM.
For more details, and examples of using these macros, see https://developer.mozilla.org/en/Using_RAII_classes_in_Mozilla