[clang-tools-extra] Add refactoring tool to convert between ternary (?:) expressions and equivalent if/else statements (PR #166822)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 7 10:33:29 PST 2025
================
@@ -58,21 +58,25 @@ void ConditionalToIfCheck::check(const MatchFinder::MatchResult &Result) {
const SourceManager &SM = *Result.SourceManager;
- auto Diag = diag(Ternary->getBeginLoc(),
- "replace ternary operator with if/else statement for readability");
+ auto Diag =
+ diag(Ternary->getBeginLoc(),
+ "replace ternary operator with if/else statement for readability");
// Extract source text for condition, true and false expressions
- std::string CondStr = Lexer::getSourceText(
- CharSourceRange::getTokenRange(Cond->getSourceRange()), SM,
- Result.Context->getLangOpts()).str();
+ std::string CondStr = Lexer::getSourceText(CharSourceRange::getTokenRange(
----------------
EugeneZelenko wrote:
```suggestion
const std::string CondStr = Lexer::getSourceText(CharSourceRange::getTokenRange(
```
Same below. See https://clang.llvm.org/extra/clang-tidy/checks/misc/const-correctness.html.
https://github.com/llvm/llvm-project/pull/166822
More information about the cfe-commits
mailing list