aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
diff options
context:
space:
mode:
authorAndrey <andrey.a.davydov@gmail.com>2025-08-03 12:39:39 +0200
committerGitHub <noreply@github.com>2025-08-03 13:39:39 +0300
commitc3902e46b748cd808fbffeea25489bb41b15a6b2 (patch)
treea1512955f16ab46b47b4c7d23a844d1a6ada8242 /clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
parent5325f2b93065ed2981d51a266bea54c0f5ebd632 (diff)
downloadllvm-c3902e46b748cd808fbffeea25489bb41b15a6b2.zip
llvm-c3902e46b748cd808fbffeea25489bb41b15a6b2.tar.gz
llvm-c3902e46b748cd808fbffeea25489bb41b15a6b2.tar.bz2
[clang-tidy] fix `bugprone-narrowing-conversions` false positive for conditional expression (#139474)
Let's consider the following code from the issue #139467: ```c void test(int cond, char c) { char ret = cond > 0 ? ':' : c; } ``` Initializer of `ret` looks the following: ``` -ImplicitCastExpr 'char' <IntegralCast> `-ConditionalOperator 'int' |-BinaryOperator 'int' '>' | |-ImplicitCastExpr 'int' <LValueToRValue> | | `-DeclRefExpr 'int' lvalue ParmVar 'cond' 'int' | `-IntegerLiteral 'int' 0 |-CharacterLiteral 'int' 58 `-ImplicitCastExpr 'int' <IntegralCast> `-ImplicitCastExpr 'char' <LValueToRValue> `-DeclRefExpr 'char' lvalue ParmVar 'c' 'char' ``` So it could be seen that `RHS` of the conditional operator is `DeclRefExpr 'c'` which is casted to `int` and then the whole conditional expression is casted to 'char'. But this last conversion is not narrowing, because `RHS` was `char` _initially_. We should just remove the cast from `char` to `int` before the narrowing conversion check. Fixes #139467
Diffstat (limited to 'clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp')
0 files changed, 0 insertions, 0 deletions