PiotrZSL updated this revision to Diff 508411. PiotrZSL marked an inline comment as done. PiotrZSL added a comment.
Use auto Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D146904/new/ https://reviews.llvm.org/D146904 Files: clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp clang-tools-extra/test/clang-tidy/checkers/readability/redundant-declaration.cpp Index: clang-tools-extra/test/clang-tidy/checkers/readability/redundant-declaration.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/readability/redundant-declaration.cpp +++ clang-tools-extra/test/clang-tidy/checkers/readability/redundant-declaration.cpp @@ -120,3 +120,9 @@ // CHECK-MESSAGES-NOMSCOMPAT: :[[@LINE-1]]:20: warning: redundant 'g' declaration // CHECK-FIXES-NOMSCOMPAT: {{^}}// extern g{{$}} #endif + +// PR42068 +extern "C" int externX; +int dumyBegin;extern "C" int externX;int dummyEnd; +// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: redundant 'externX' declaration [readability-redundant-declaration] +// CHECK-FIXES: {{^}}int dumyBegin;int dummyEnd;{{$}} Index: clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp +++ clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp @@ -35,7 +35,8 @@ functionDecl(unless(anyOf( isDefinition(), isDefaulted(), doesDeclarationForceExternallyVisibleDefinition(), - hasAncestor(friendDecl())))))) + hasAncestor(friendDecl()))))), + optionally(hasParent(linkageSpecDecl().bind("extern")))) .bind("Decl"), this); } @@ -78,9 +79,17 @@ D->getSourceRange().getEnd(), 0, SM, Result.Context->getLangOpts()); { auto Diag = diag(D->getLocation(), "redundant %0 declaration") << D; - if (!MultiVar && !DifferentHeaders) - Diag << FixItHint::CreateRemoval( - SourceRange(D->getSourceRange().getBegin(), EndLoc)); + if (!MultiVar && !DifferentHeaders) { + SourceLocation BeginLoc; + if (const auto *Extern = + Result.Nodes.getNodeAs<LinkageSpecDecl>("extern"); + Extern && !Extern->hasBraces()) + BeginLoc = Extern->getExternLoc(); + else + BeginLoc = D->getSourceRange().getBegin(); + + Diag << FixItHint::CreateRemoval(SourceRange(BeginLoc, EndLoc)); + } } diag(Prev->getLocation(), "previously declared here", DiagnosticIDs::Note); }
Index: clang-tools-extra/test/clang-tidy/checkers/readability/redundant-declaration.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/readability/redundant-declaration.cpp +++ clang-tools-extra/test/clang-tidy/checkers/readability/redundant-declaration.cpp @@ -120,3 +120,9 @@ // CHECK-MESSAGES-NOMSCOMPAT: :[[@LINE-1]]:20: warning: redundant 'g' declaration // CHECK-FIXES-NOMSCOMPAT: {{^}}// extern g{{$}} #endif + +// PR42068 +extern "C" int externX; +int dumyBegin;extern "C" int externX;int dummyEnd; +// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: redundant 'externX' declaration [readability-redundant-declaration] +// CHECK-FIXES: {{^}}int dumyBegin;int dummyEnd;{{$}} Index: clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp +++ clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp @@ -35,7 +35,8 @@ functionDecl(unless(anyOf( isDefinition(), isDefaulted(), doesDeclarationForceExternallyVisibleDefinition(), - hasAncestor(friendDecl())))))) + hasAncestor(friendDecl()))))), + optionally(hasParent(linkageSpecDecl().bind("extern")))) .bind("Decl"), this); } @@ -78,9 +79,17 @@ D->getSourceRange().getEnd(), 0, SM, Result.Context->getLangOpts()); { auto Diag = diag(D->getLocation(), "redundant %0 declaration") << D; - if (!MultiVar && !DifferentHeaders) - Diag << FixItHint::CreateRemoval( - SourceRange(D->getSourceRange().getBegin(), EndLoc)); + if (!MultiVar && !DifferentHeaders) { + SourceLocation BeginLoc; + if (const auto *Extern = + Result.Nodes.getNodeAs<LinkageSpecDecl>("extern"); + Extern && !Extern->hasBraces()) + BeginLoc = Extern->getExternLoc(); + else + BeginLoc = D->getSourceRange().getBegin(); + + Diag << FixItHint::CreateRemoval(SourceRange(BeginLoc, EndLoc)); + } } diag(Prev->getLocation(), "previously declared here", DiagnosticIDs::Note); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits