[cfe-dev] clang-tidy FixItHint::CreateRemoval -- trailing semicolon stays

Piotr Dziwinski via cfe-dev cfe-dev at lists.llvm.org
Fri Feb 5 00:03:09 PST 2016


> Yes this is a good idea, thanks. Sadly I need to do it at the very end 
> (your code seems to be able to trigger output (call diag()) based upon 
> function declaration scope.
>
> I'm trying out using the destruction of the check class to report all 
> the issues. So, for example:
>
> clang::SourceLocation foo;
>
> UsingCheck::~UsingCheck() {
>   std::cerr << "** destroy of UsingCheck instance\n";
>   diag(foo, "bogus error for testing");
> }
>
> where I just stash a SourceLocation. The code above works (a simple 
> try-it-out test). I'm not sure if a destructor of a ClangTidyCheck 
> class is allowed to do this.  And I still need to stash SourceLocation 
> and SourceRange objects for this to work.

It's safe to stash SourceLocation and SourceRange objects, as long as 
the SourceManager object with which they are associated lives on. In 
clang-tidy, that would be until the check is finished on current 
translation unit and then destroyed.

But I wouldn't depend on such tricky behavior in the destructor. A 
better place to handle it would be in function onEndOfTranslationUnit() 
overridden from MatchFinder::MatchCallback.

Best regards,
Piotr Dziwinski



More information about the cfe-dev mailing list