diff --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp index 8cfda506fc254..febdf19e695cd 100644 --- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp +++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp @@ -304,6 +304,16 @@ class ASTWalker : public RecursiveASTVisitor { } return RecursiveASTVisitor::TraverseTemplateArgumentLoc(TL); } + + bool VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) { + // Reliance on initializer_lists requires std::initializer_list to be + // visible per standard. So report a reference to it, otherwise include of + // `` might not receive any use. + report(E->getExprLoc(), + const_cast(E->getBestDynamicClassType()), + RefType::Implicit); + return true; + } }; } // namespace diff --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp index 525f645ec91ef..3a86f36e3964f 100644 --- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp +++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp @@ -282,7 +282,6 @@ template<> void $ambiguous^function(int); // full specialization "using ns::^function;"); } - TEST(WalkAST, Alias) { testWalk(R"cpp( namespace ns { int x; } @@ -510,5 +509,14 @@ TEST(WalkAST, Enums) { testWalk("enum class E : int {};", "enum class ^E : int ;"); } +TEST(WalkAST, InitializerList) { + testWalk(R"cpp( + namespace std { + template struct $implicit^initializer_list {}; + })cpp", + R"cpp( + const char* s = ""; + auto sx = ^{s};)cpp"); +} } // namespace } // namespace clang::include_cleaner