class SavePendingInstantiationsAndVTableUsesRAII {
public:
- SavePendingInstantiationsAndVTableUsesRAII(Sema &S): S(S) {
+ SavePendingInstantiationsAndVTableUsesRAII(Sema &S, bool Enabled)
+ : S(S), Enabled(Enabled) {
+ if (!Enabled) return;
+
SavedPendingInstantiations.swap(S.PendingInstantiations);
SavedVTableUses.swap(S.VTableUses);
}
~SavePendingInstantiationsAndVTableUsesRAII() {
+ if (!Enabled) return;
+
// Restore the set of pending vtables.
assert(S.VTableUses.empty() &&
"VTableUses should be empty before it is discarded.");
Sema &S;
SmallVector<VTableUse, 16> SavedVTableUses;
std::deque<PendingImplicitInstantiation> SavedPendingInstantiations;
+ bool Enabled;
};
/// \brief The queue of implicit template instantiations that are required
// it marks vtables used in late parsed templates as used.
SavePendingLocalImplicitInstantiationsRAII
SavedPendingLocalImplicitInstantiations(*this);
- std::unique_ptr<SavePendingInstantiationsAndVTableUsesRAII>
- SavePendingInstantiationsAndVTableUses;
- if (Recursive) {
- SavePendingInstantiationsAndVTableUses.reset(
- new SavePendingInstantiationsAndVTableUsesRAII(*this));
- }
+ SavePendingInstantiationsAndVTableUsesRAII
+ SavePendingInstantiationsAndVTableUses(*this, /*Enabled=*/Recursive);
// Call the LateTemplateParser callback if there is a need to late parse
// a templated function definition.
// instantiation of this template.
PerformPendingInstantiations();
- // Restore PendingInstantiations and VTableUses.
- SavePendingInstantiationsAndVTableUses.reset();
+ // PendingInstantiations and VTableUses are restored through
+ // SavePendingInstantiationsAndVTableUses's destructor.
}
}
// If we're performing recursive template instantiation, create our own
// queue of pending implicit instantiations that we will instantiate
// later, while we're still within our own instantiation context.
- std::unique_ptr<SavePendingInstantiationsAndVTableUsesRAII>
- SavePendingInstantiationsAndVTableUses;
- if (Recursive) {
- SavePendingInstantiationsAndVTableUses.reset(
- new SavePendingInstantiationsAndVTableUsesRAII(*this));
- }
+ SavePendingInstantiationsAndVTableUsesRAII
+ SavePendingInstantiationsAndVTableUses(*this, /*Enabled=*/Recursive);
LocalInstantiationScope Local(*this);
// instantiation of this template.
PerformPendingInstantiations();
- // Restore PendingInstantiations and VTableUses.
- SavePendingInstantiationsAndVTableUses.reset();
+ // PendingInstantiations and VTableUses are restored through
+ // SavePendingInstantiationsAndVTableUses's destructor.
}
}
// while we're still within our own instantiation context.
SavePendingLocalImplicitInstantiationsRAII
SavedPendingLocalImplicitInstantiations(*this);
- std::unique_ptr<SavePendingInstantiationsAndVTableUsesRAII>
- SavePendingInstantiationsAndVTableUses;
- if (Recursive) {
- SavePendingInstantiationsAndVTableUses.reset(
- new SavePendingInstantiationsAndVTableUsesRAII(*this));
- }
+ SavePendingInstantiationsAndVTableUsesRAII
+ SavePendingInstantiationsAndVTableUses(*this, /*Enabled=*/Recursive);
// Enter the scope of this instantiation. We don't use
// PushDeclContext because we don't have a scope.
// instantiation of this template.
PerformPendingInstantiations();
- // Restore PendingInstantiations and VTableUses.
- SavePendingInstantiationsAndVTableUses.reset();
+ // PendingInstantiations and VTableUses are restored through
+ // SavePendingInstantiationsAndVTableUses's destructor.
}
}