Issue 182132
Summary readability-redundant-casting false-negatives when casting mathmatical operations on values of differing types
Labels new issue
Assignees
Reporter nick-potenski
    `readability-redundant-casting` does not produce warnings as expected when a mathematical operation performed on values of different types is cast to the operation's resulting, promoted type.

```c++
#include <cstdint>

constexpr auto basic_value{static_cast<float>(1.0f)};  // warns as expected
constexpr auto same_types{static_cast<float>(1.0f + 1.0f)}; // warns as expected
constexpr auto diff_types_float{static_cast<float>(1.0f + 1)}; // does not warn as expected 
constexpr auto diff_types_int{static_cast<int>(1 + static_cast<uint8_t>(1))}; // does not warn as expected
``` 

produces:

```
<source>:3:28: warning: redundant explicit casting to the same type 'float' as the sub-_expression_, remove this casting [readability-redundant-casting]
    3 | constexpr auto basic_value{static_cast<float>(1.0f)};  // warns as expected
      | ^~~~~~~~~~~~~~~~~~~    ~
<source>:4:27: warning: redundant explicit casting to the same type 'float' as the sub-_expression_, remove this casting [readability-redundant-casting]
    4 | constexpr auto same_types{static_cast<float>(1.0f + 1.0f)}; // warns as expected
      | ^~~~~~~~~~~~~~~~~~~           ~
      | (                             )
4 warnings generated.
``` 

Compiler explorer link for above code: https://godbolt.org/z/e7cKKxYfa.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to