[clang-tools-extra] [clang-tidy] Fix false positive in misc-redundant-expression with type aliases (PR #198085)

via cfe-commits cfe-commits at lists.llvm.org
Sat May 30 22:39:43 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE LINT COMMENT: clang-tidy-->


:warning: C/C++ code linter, clang-tidy found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

```bash

git diff -U0 origin/main...HEAD -- clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp |
python3 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py   -path build -p1 -quiet
```

</details>

<details>
<summary>
View the output from clang-tidy here.
</summary>

```
clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp:147:5: warning: variable 'LeftPack' of type 'ArrayRef<TemplateArgument>' can be declared 'const' [misc-const-correctness]
  147 |     ArrayRef<TemplateArgument> LeftPack = Left.pack_elements();
      |     ^
      |                                const 
clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp:148:5: warning: variable 'RightPack' of type 'ArrayRef<TemplateArgument>' can be declared 'const' [misc-const-correctness]
  148 |     ArrayRef<TemplateArgument> RightPack = Right.pack_elements();
      |     ^
      |                                const 
clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp:231:5: warning: variable 'LeftNamespace' of type 'NamespaceAndPrefix' can be declared 'const' [misc-const-correctness]
  231 |     NamespaceAndPrefix LeftNamespace = Left.getAsNamespaceAndPrefix();
      |     ^
      |                        const 
clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp:232:5: warning: variable 'RightNamespace' of type 'NamespaceAndPrefix' can be declared 'const' [misc-const-correctness]
  232 |     NamespaceAndPrefix RightNamespace = Right.getAsNamespaceAndPrefix();
      |     ^
      |                        const 
clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp:252:3: warning: variable 'LeftSpecifier' of type 'NestedNameSpecifier' can be declared 'const' [misc-const-correctness]
  252 |   NestedNameSpecifier LeftSpecifier = Left.getNestedNameSpecifier();
      |   ^
      |                       const 
clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp:253:3: warning: variable 'RightSpecifier' of type 'NestedNameSpecifier' can be declared 'const' [misc-const-correctness]
  253 |   NestedNameSpecifier RightSpecifier = Right.getNestedNameSpecifier();
      |   ^
      |                       const 
clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp:262:5: warning: variable 'LeftNamespace' of type 'NamespaceAndPrefixLoc' can be declared 'const' [misc-const-correctness]
  262 |     NamespaceAndPrefixLoc LeftNamespace = Left.getAsNamespaceAndPrefix();
      |     ^
      |                           const 
clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp:263:5: warning: variable 'RightNamespace' of type 'NamespaceAndPrefixLoc' can be declared 'const' [misc-const-correctness]
  263 |     NamespaceAndPrefixLoc RightNamespace = Right.getAsNamespaceAndPrefix();
      |     ^
      |                           const 
clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp:269:5: warning: variable 'LeftLoc' of type 'TypeLoc' can be declared 'const' [misc-const-correctness]
  269 |     TypeLoc LeftLoc = Left.getAsTypeLoc();
      |     ^
      |             const 
clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp:270:5: warning: variable 'RightLoc' of type 'TypeLoc' can be declared 'const' [misc-const-correctness]
  270 |     TypeLoc RightLoc = Right.getAsTypeLoc();
      |     ^
      |             const 
clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp:322:5: warning: variable 'LeftArguments' of type 'ArrayRef<TemplateArgument>' can be declared 'const' [misc-const-correctness]
  322 |     ArrayRef<TemplateArgument> LeftArguments =
      |     ^
      |                                const 
clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp:324:5: warning: variable 'RightArguments' of type 'ArrayRef<TemplateArgument>' can be declared 'const' [misc-const-correctness]
  324 |     ArrayRef<TemplateArgument> RightArguments =
      |     ^
      |                                const
```

</details>


https://github.com/llvm/llvm-project/pull/198085


More information about the cfe-commits mailing list