[PATCH] Add a level parameter to ClangTidyCheck::diag.

Alp Toker alp at nuanti.com
Sun Mar 2 08:18:12 PST 2014


On 02/03/2014 12:25, Peter Collingbourne wrote:
> Hi alexfh,
>
> The goal is to make it possible for checks to emit diagnostics at levels
> other than 'warning'.
>
> http://llvm-reviews.chandlerc.com/D2913
>
> Files:
>    clang-tidy/ClangTidy.cpp
>    clang-tidy/ClangTidy.h
>
> Index: clang-tidy/ClangTidy.cpp
> ===================================================================
> --- clang-tidy/ClangTidy.cpp
> +++ clang-tidy/ClangTidy.cpp
> @@ -226,8 +226,9 @@
>     return EnableChecks.match(Name) && !DisableChecks.match(Name);
>   }
>   
> -DiagnosticBuilder ClangTidyCheck::diag(SourceLocation Loc, StringRef Message) {
> -  return Context->diag(CheckName, Loc, Message);
> +DiagnosticBuilder ClangTidyCheck::diag(SourceLocation Loc, StringRef Message,
> +                                       DiagnosticIDs::Level Level) {
> +  return Context->diag(CheckName, Loc, Message, Level);
>   }
>   
>   void ClangTidyCheck::run(const ast_matchers::MatchFinder::MatchResult &Result) {
> Index: clang-tidy/ClangTidy.h
> ===================================================================
> --- clang-tidy/ClangTidy.h
> +++ clang-tidy/ClangTidy.h
> @@ -76,7 +76,8 @@
>     void setContext(ClangTidyContext *Ctx) { Context = Ctx; }
>   
>     /// \brief Add a diagnostic with the check's name.
> -  DiagnosticBuilder diag(SourceLocation Loc, StringRef Description);
> +  DiagnosticBuilder diag(SourceLocation Loc, StringRef Description,
> +                         DiagnosticIDs::Level Level = DiagnosticIDs::Warning);

Could you order the parameters Loc, Level, FormatString and drop the 
default argument?

That'll provide visual consistency with the output as well as internal 
consistency with clang's own getCustomDiagID(Level L, StringRef 
FormatString).

That way it becomes kind of a shorthand for diag(getCustomDiagID(...)) 
<< ... which is a step towards unifying built-in and custom diagnostic IDs.

Alp.


>   
>     /// \brief Sets the check name. Intended to be used by the clang-tidy
>     /// framework. Can be called only once.
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

-- 
http://www.nuanti.com
the browser experts




More information about the cfe-commits mailing list