Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "RedundantCastingCheck.h"
#include "../utils/FixItHintUtils.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/TypeBase.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?

#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Lex/Lexer.h"

Expand All @@ -29,7 +30,7 @@ static bool areTypesEqual(QualType S, QualType D) {
const QualType PtrD = D->getPointeeType();

if (!PtrS.isNull() && !PtrD.isNull())
return areTypesEqual(PtrS, PtrD);
return areTypesEqual(PtrS.IgnoreParens(), PtrD.IgnoreParens());

const DeducedType *DT = S->getContainedDeducedType();
if (DT && DT->isDeduced())
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,10 @@ Changes in existing checks
<clang-tidy/checks/readability/qualified-auto>` check by adding the option
`IgnoreAliasing`, that allows not looking at underlying types of type aliases.

- Improved :doc:`readability-redundant-casting
<clang-tidy/checks/readability/redundant-casting>` check by fixing false
negatives when explicitly cast from function pointer.

- Improved :doc:`readability-uppercase-literal-suffix
<clang-tidy/checks/readability/uppercase-literal-suffix>` check to recognize
literal suffixes added in C++23 and C23.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,13 @@ void testRedundantDependentNTTPCasting() {
// CHECK-MESSAGES: :[[@LINE-4]]:25: note: source type originates from referencing this non-type template parameter
// CHECK-FIXES: T a = V;
}

namespace gh170476 {
int f(void);
int g1() {
int (*fp)() = (int(*)(void))&f;
// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: redundant explicit casting to the same type 'int (*)()' as the sub-expression, remove this casting [readability-redundant-casting]
// CHECK-FIXES: int (*fp)() = (&f);
return fp();
}
} // namespace gh170476