Make DiagnosticsEngine::takeClient return std::unique_ptr<>. Updated
callers to store conditional ownership using a pair of pointer and unique_ptr
instead of a pointer + bool. Updated code that temporarily registers clients to
use the non-owning registration (+ removed extra calls to takeClient).
Details
Diff Detail
Event Timeline
Looks mostly like a sort-of improvement, with a bit more tidying up that could be done in follow-up patches (though I'd slightly prefer to drop the !! before committing this at least, and double-check the owner naming convention in existing cases to be consistent)
include/clang/Basic/Diagnostic.h | ||
---|---|---|
370 | I don't think !! is idiomatic in the LLVM codebase (though I may be incorrect) & probably just (bool) or static_cast<bool> would be more consistent. | |
include/clang/Rewrite/Frontend/FixItRewriter.h | ||
69 | What's the naming convention for other T*+unique_ptr<T> combos like this? I think I introduced the first few of these (see the email thread on the "maybe owning" pointer semantics in llvm-dev/cfe-dev for a list of other cases) and I might've used "*Owner" rather than "Owning*" - it'd be nice to be consistent (so they're easy to find and cleanup later). | |
lib/Frontend/Rewrite/FixItRewriter.cpp | ||
45 | As mentioned above (hmm, should this class use the CaptureDroppedDiagnostics? I guess not (it probably does other things) - but maybe we should have a common scoped "replace the DiagnosticConsumer" device that could be used in both places? - though that's probably overkill once we fix the ownership one way or another) | |
lib/Frontend/VerifyDiagnosticConsumer.cpp | ||
46 | While it didn't have it before - this might deserve a comment. |
include/clang/Basic/Diagnostic.h | ||
---|---|---|
370 | Changed "!!" to "!= nullptr". | |
include/clang/Rewrite/Frontend/FixItRewriter.h | ||
69 | Renamed Owning* to *Owner or just Owner depending on wether the latter is ambiguous in the context or not. | |
lib/Frontend/Rewrite/FixItRewriter.cpp | ||
45 | A separate scoped diagnostic client replacer would be nice, but it's slightly out of scope for this patch. | |
lib/Frontend/VerifyDiagnosticConsumer.cpp | ||
46 | I'm not sure I completely understand what's going on here. I'm actually not sure if this code is even correct. I just attempted to leave the existing behavior here. So I'd refrain from writing a misleading comment until I figure this out. |
I don't think !! is idiomatic in the LLVM codebase (though I may be incorrect) & probably just (bool) or static_cast<bool> would be more consistent.