Skip to content

Commit ae0813f

Browse files
committed
Revert "[clang-tidy] fix false positives for the functions with the same name as standard library functions in misc-include-cleaner (#94923)"
This reverts commit 1bae108. Also add some test cases to prevent further regressions.
1 parent edd6f0c commit ae0813f

File tree

4 files changed

+11
-30
lines changed

4 files changed

+11
-30
lines changed

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,6 @@ Changes in existing checks
341341
<clang-tidy/checks/misc/header-include-cycle>` check by avoiding crash for self
342342
include cycles.
343343

344-
- Improved :doc:`misc-include-cleaner
345-
<clang-tidy/checks/misc/include-cleaner>` check by avoiding false positives for
346-
the functions with the same name as standard library functions.
347-
348344
- Improved :doc:`misc-unused-using-decls
349345
<clang-tidy/checks/misc/unused-using-decls>` check by replacing the local
350346
option `HeaderFileExtensions` by the global option of the same name.

clang-tools-extra/include-cleaner/lib/LocateSymbol.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "clang/AST/DeclTemplate.h"
1515
#include "clang/Tooling/Inclusions/StandardLibrary.h"
1616
#include "llvm/Support/Casting.h"
17-
#include "llvm/Support/raw_ostream.h"
1817
#include <utility>
1918
#include <vector>
2019

@@ -41,11 +40,8 @@ Hints declHints(const Decl *D) {
4140
std::vector<Hinted<SymbolLocation>> locateDecl(const Decl &D) {
4241
std::vector<Hinted<SymbolLocation>> Result;
4342
// FIXME: Should we also provide physical locations?
44-
if (auto SS = tooling::stdlib::Recognizer()(&D)) {
45-
Result.push_back({*SS, Hints::CompleteSymbol});
46-
if (!D.hasBody())
47-
return Result;
48-
}
43+
if (auto SS = tooling::stdlib::Recognizer()(&D))
44+
return {{*SS, Hints::CompleteSymbol}};
4945
// FIXME: Signal foreign decls, e.g. a forward declaration not owned by a
5046
// library. Some useful signals could be derived by checking the DeclContext.
5147
// Most incidental forward decls look like:

clang-tools-extra/include-cleaner/unittests/FindHeadersTest.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -619,26 +619,23 @@ TEST_F(HeadersForSymbolTest, AmbiguousStdSymbolsUsingShadow) {
619619

620620

621621
TEST_F(HeadersForSymbolTest, StandardHeaders) {
622-
Inputs.Code = "void assert();";
622+
Inputs.Code = R"cpp(
623+
#include "stdlib_internal.h"
624+
void assert();
625+
void foo() { assert(); }
626+
)cpp";
627+
Inputs.ExtraFiles["stdlib_internal.h"] = "void assert();";
623628
buildAST();
624629
EXPECT_THAT(
625630
headersFor("assert"),
626631
// Respect the ordering from the stdlib mapping.
632+
// FIXME: Report physical locations too, stdlib_internal.h and main-file
633+
// should also be candidates. But they should be down-ranked compared to
634+
// stdlib providers.
627635
UnorderedElementsAre(tooling::stdlib::Header::named("<cassert>"),
628636
tooling::stdlib::Header::named("<assert.h>")));
629637
}
630638

631-
TEST_F(HeadersForSymbolTest, NonStandardHeaders) {
632-
Inputs.Code = "void assert() {}";
633-
buildAST();
634-
EXPECT_THAT(
635-
headersFor("assert"),
636-
// Respect the ordering from the stdlib mapping.
637-
UnorderedElementsAre(physicalHeader("input.mm"),
638-
tooling::stdlib::Header::named("<cassert>"),
639-
tooling::stdlib::Header::named("<assert.h>")));
640-
}
641-
642639
TEST_F(HeadersForSymbolTest, ExporterNoNameMatch) {
643640
Inputs.Code = R"cpp(
644641
#include "exporter/foo.h"

clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,3 @@ std::string HelloString;
1515
// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: no header providing "std::string" is directly included [misc-include-cleaner]
1616
int FooBarResult = foobar();
1717
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: no header providing "foobar" is directly included [misc-include-cleaner]
18-
19-
namespace valid {
20-
21-
namespace gh93335 {
22-
void log2() {}
23-
} // namespace gh93335
24-
25-
} // namespace valid

0 commit comments

Comments
 (0)