================ @@ -0,0 +1,105 @@ +//===--- UseConcisePreprocessorDirectivesCheck.cpp - clang-tidy -----------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "UseConcisePreprocessorDirectivesCheck.h" +#include "clang/Basic/TokenKinds.h" +#include "clang/Lex/Lexer.h" +#include "clang/Lex/PPCallbacks.h" +#include "clang/Lex/Preprocessor.h" + +namespace clang::tidy::modernize { + +namespace { + +class IfPreprocessorCallbacks final : public PPCallbacks { +public: + IfPreprocessorCallbacks(ClangTidyCheck &Check, Preprocessor &PP) + : Check(Check), PP(PP) {} + + void If(SourceLocation Loc, SourceRange ConditionRange, + ConditionValueKind) override { + impl(Loc, ConditionRange, {"ifdef", "ifndef"}); + } + + void Elif(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind, + SourceLocation) override { + if (PP.getLangOpts().C23 || PP.getLangOpts().CPlusPlus23) { + impl(Loc, ConditionRange, {"elifdef", "elifndef"}); + } + } + +private: + void impl(SourceLocation DirectiveLoc, SourceRange ConditionRange, + const llvm::StringLiteral (&Replacements)[2]) { + StringRef Condition = ---------------- vbvictor wrote:
I feel that we should generally follow const correctness, at least for new checks/features. https://github.com/llvm/llvm-project/pull/146830 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits