diff --git a/clang-tools-extra/clangd/AST.cpp b/clang-tools-extra/clangd/AST.cpp --- a/clang-tools-extra/clangd/AST.cpp +++ b/clang-tools-extra/clangd/AST.cpp @@ -438,7 +438,7 @@ const AutoType *AT = D->getReturnType()->getContainedAutoType(); if (AT && !AT->getDeducedType().isNull()) { DeducedType = AT->getDeducedType(); - } else if (auto DT = dyn_cast(D->getReturnType())) { + } else if (const auto *DT = dyn_cast(D->getReturnType())) { // auto in a trailing return type just points to a DecltypeType and // getContainedAutoType does not unwrap it. if (!DT->getUnderlyingType().isNull()) diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -437,7 +437,7 @@ template const std::string *onlyValue() const { auto B = Bundled.begin(), E = Bundled.end(); - for (auto I = B + 1; I != E; ++I) + for (const auto *I = B + 1; I != E; ++I) if (I->*Member != B->*Member) return nullptr; return &(B->*Member); @@ -445,7 +445,7 @@ template const bool *onlyValue() const { auto B = Bundled.begin(), E = Bundled.end(); - for (auto I = B + 1; I != E; ++I) + for (const auto *I = B + 1; I != E; ++I) if (I->*Member != B->*Member) return nullptr; return &(B->*Member); diff --git a/clang-tools-extra/clangd/ExpectedTypes.cpp b/clang-tools-extra/clangd/ExpectedTypes.cpp --- a/clang-tools-extra/clangd/ExpectedTypes.cpp +++ b/clang-tools-extra/clangd/ExpectedTypes.cpp @@ -53,7 +53,7 @@ auto T = VD->getType(); if (T.isNull()) return llvm::None; - if (auto FuncT = T->getAs()) { + if (const auto *FuncT = T->getAs()) { // Functions are a special case. They are completed as 'foo()' and we want // to match their return type rather than the function type itself. // FIXME(ibiryukov): in some cases, we might want to avoid completing `()` diff --git a/clang-tools-extra/clangd/FindSymbols.cpp b/clang-tools-extra/clangd/FindSymbols.cpp --- a/clang-tools-extra/clangd/FindSymbols.cpp +++ b/clang-tools-extra/clangd/FindSymbols.cpp @@ -483,7 +483,7 @@ if (!llvm::isa(D)) return VisitKind::No; - if (auto Func = llvm::dyn_cast(D)) { + if (auto *Func = llvm::dyn_cast(D)) { // Some functions are implicit template instantiations, those should be // ignored. if (auto *Info = Func->getTemplateSpecializationInfo()) { diff --git a/clang-tools-extra/clangd/HeaderSourceSwitch.cpp b/clang-tools-extra/clangd/HeaderSourceSwitch.cpp --- a/clang-tools-extra/clangd/HeaderSourceSwitch.cpp +++ b/clang-tools-extra/clangd/HeaderSourceSwitch.cpp @@ -25,13 +25,13 @@ llvm::StringRef PathExt = llvm::sys::path::extension(OriginalFile); // Lookup in a list of known extensions. - auto SourceIter = + auto *SourceIter = llvm::find_if(SourceExtensions, [&PathExt](PathRef SourceExt) { return SourceExt.equals_insensitive(PathExt); }); bool IsSource = SourceIter != std::end(SourceExtensions); - auto HeaderIter = + auto *HeaderIter = llvm::find_if(HeaderExtensions, [&PathExt](PathRef HeaderExt) { return HeaderExt.equals_insensitive(PathExt); }); diff --git a/clang-tools-extra/clangd/Hover.cpp b/clang-tools-extra/clangd/Hover.cpp --- a/clang-tools-extra/clangd/Hover.cpp +++ b/clang-tools-extra/clangd/Hover.cpp @@ -83,7 +83,7 @@ Policy.SuppressScope = true; return declaredType(D).getAsString(Policy); } - if (auto RD = dyn_cast(D)) + if (const auto *RD = dyn_cast(D)) return ("(anonymous " + RD->getKindName() + ")").str(); return std::string(""); }; diff --git a/clang-tools-extra/clangd/TUScheduler.cpp b/clang-tools-extra/clangd/TUScheduler.cpp --- a/clang-tools-extra/clangd/TUScheduler.cpp +++ b/clang-tools-extra/clangd/TUScheduler.cpp @@ -1717,7 +1717,7 @@ // nth_element needs a mutable array, take the chance to bound the data size. History = History.take_back(15); llvm::SmallVector Recent(History.begin(), History.end()); - auto Median = Recent.begin() + Recent.size() / 2; + auto *Median = Recent.begin() + Recent.size() / 2; std::nth_element(Recent.begin(), Median, Recent.end()); clock::duration Target = diff --git a/clang-tools-extra/clangd/index/IndexAction.cpp b/clang-tools-extra/clangd/index/IndexAction.cpp --- a/clang-tools-extra/clangd/index/IndexAction.cpp +++ b/clang-tools-extra/clangd/index/IndexAction.cpp @@ -61,7 +61,7 @@ return; const auto FileID = SM.getFileID(Loc); - const auto File = SM.getFileEntryForID(FileID); + const auto *const File = SM.getFileEntryForID(FileID); auto URI = toURI(File); if (!URI) return; diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp --- a/clang-tools-extra/clangd/index/SymbolCollector.cpp +++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp @@ -43,7 +43,7 @@ /// If \p ND is a template specialization, returns the described template. /// Otherwise, returns \p ND. const NamedDecl &getTemplateOrThis(const NamedDecl &ND) { - if (auto T = ND.getDescribedTemplate()) + if (auto *T = ND.getDescribedTemplate()) return *T; return ND; } diff --git a/clang-tools-extra/clangd/index/dex/Iterator.cpp b/clang-tools-extra/clangd/index/dex/Iterator.cpp --- a/clang-tools-extra/clangd/index/dex/Iterator.cpp +++ b/clang-tools-extra/clangd/index/dex/Iterator.cpp @@ -77,7 +77,7 @@ private: llvm::raw_ostream &dump(llvm::raw_ostream &OS) const override { OS << "(& "; - auto Separator = ""; + const auto *Separator = ""; for (const auto &Child : Children) { OS << Separator << *Child; Separator = " "; @@ -206,7 +206,7 @@ private: llvm::raw_ostream &dump(llvm::raw_ostream &OS) const override { OS << "(| "; - auto Separator = ""; + const auto *Separator = ""; for (const auto &Child : Children) { OS << Separator << *Child; Separator = " "; diff --git a/clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp b/clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp @@ -38,7 +38,7 @@ Expected AnnotateHighlightings::apply(const Selection &Inputs) { const Decl *CommonDecl = nullptr; - for (auto N = Inputs.ASTSelection.commonAncestor(); N && !CommonDecl; + for (const auto *N = Inputs.ASTSelection.commonAncestor(); N && !CommonDecl; N = N->Parent) CommonDecl = N->ASTNode.get(); diff --git a/clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp b/clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp @@ -342,13 +342,13 @@ // Because canonical declaration points to template decl instead of // specialization. const FunctionDecl *findTarget(const FunctionDecl *FD) { - auto CanonDecl = FD->getCanonicalDecl(); + const auto *CanonDecl = FD->getCanonicalDecl(); if (!FD->isFunctionTemplateSpecialization() || CanonDecl == FD) return CanonDecl; // For specializations CanonicalDecl is the TemplatedDecl, which is not the // target we want to inline into. Instead we traverse previous decls to find // the first forward decl for this specialization. - auto PrevDecl = FD; + const auto *PrevDecl = FD; while (PrevDecl->getPreviousDecl() != CanonDecl) { PrevDecl = PrevDecl->getPreviousDecl(); assert(PrevDecl && "Found specialization without template decl"); diff --git a/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp b/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp @@ -34,7 +34,7 @@ const char *id() const override final; bool prepare(const Selection &Inputs) override { - for (auto N = Inputs.ASTSelection.commonAncestor(); N && !Node; + for (const auto *N = Inputs.ASTSelection.commonAncestor(); N && !Node; N = N->Parent) if (dumpable(N->ASTNode)) Node = N->ASTNode; diff --git a/clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp b/clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp --- a/clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp +++ b/clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp @@ -52,7 +52,7 @@ llvm::ArrayRef Spelled, unsigned CursorOffset) { // Find the token that strats after the offset, then look at a previous one. - auto It = llvm::partition_point(Spelled, [&](const syntax::Token &T) { + const auto *It = llvm::partition_point(Spelled, [&](const syntax::Token &T) { assert(T.location().isFileID()); return SM.getFileOffset(T.location()) <= CursorOffset; }); diff --git a/clang-tools-extra/clangd/unittests/ClangdTests.cpp b/clang-tools-extra/clangd/unittests/ClangdTests.cpp --- a/clang-tools-extra/clangd/unittests/ClangdTests.cpp +++ b/clang-tools-extra/clangd/unittests/ClangdTests.cpp @@ -214,7 +214,7 @@ parseSourceAndDumpAST("foo.cpp", "#include \"foo.h\"", {{"foo.h", ""}}, /*ExpectErrors=*/false); - const auto SourceContents = R"cpp( + const auto *const SourceContents = R"cpp( #include "foo.h" int b = a; )cpp"; @@ -230,7 +230,7 @@ MockCompilationDatabase CDB; ClangdServer Server(CDB, FS, ClangdServer::optsForTest(), &DiagConsumer); - const auto SourceContents = R"cpp( + const auto *const SourceContents = R"cpp( #include "foo.h" int b = a; )cpp"; @@ -265,7 +265,7 @@ MockCompilationDatabase CDB; ClangdServer Server(CDB, FS, ClangdServer::optsForTest(), &DiagConsumer); - const auto SourceContents = R"cpp( + const auto *const SourceContents = R"cpp( #include "foo.h" int b = a; )cpp"; @@ -422,7 +422,7 @@ FS.Files[StringPath] = "class mock_string {};"; auto FooCpp = testPath("foo.cpp"); - const auto SourceContents = R"cpp( + const auto *const SourceContents = R"cpp( #include mock_string x; )cpp"; @@ -431,7 +431,7 @@ runAddDocument(Server, FooCpp, SourceContents); EXPECT_FALSE(DiagConsumer.hadErrorInLastDiags()); - const auto SourceContentsWithError = R"cpp( + const auto *const SourceContentsWithError = R"cpp( #include std::string x; )cpp"; @@ -447,11 +447,11 @@ ClangdServer Server(CDB, FS, ClangdServer::optsForTest(), &DiagConsumer); auto FooCpp = testPath("foo.cpp"); - const auto SourceContents1 = R"cpp( + const auto *const SourceContents1 = R"cpp( template struct foo { T x; }; )cpp"; - const auto SourceContents2 = R"cpp( + const auto *const SourceContents2 = R"cpp( template struct bar { T x; }; )cpp"; @@ -483,7 +483,7 @@ ClangdServer Server(CDB, FS, ClangdServer::optsForTest(), &DiagConsumer); auto FooCpp = testPath("foo.cpp"); - const auto SourceContents = R"cpp( + const auto *const SourceContents = R"cpp( #ifdef WITH_ERROR this #endif @@ -587,7 +587,7 @@ ClangdServer Server(CDB, FS, ClangdServer::optsForTest(), &DiagConsumer); Path FooCpp = testPath("foo.cpp"); - const auto SourceContents = R"cpp( + const auto *const SourceContents = R"cpp( struct Something { int method(); }; @@ -653,14 +653,14 @@ // BlockingRequestInterval-request will be a blocking one. const unsigned BlockingRequestInterval = 40; - const auto SourceContentsWithoutErrors = R"cpp( + const auto *const SourceContentsWithoutErrors = R"cpp( int a; int b; int c; int d; )cpp"; - const auto SourceContentsWithErrors = R"cpp( + const auto *const SourceContentsWithErrors = R"cpp( int a = x; int b; int c; @@ -893,14 +893,14 @@ std::promise StartSecondReparse; }; - const auto SourceContentsWithoutErrors = R"cpp( + const auto *const SourceContentsWithoutErrors = R"cpp( int a; int b; int c; int d; )cpp"; - const auto SourceContentsWithErrors = R"cpp( + const auto *const SourceContentsWithErrors = R"cpp( int a = x; int b; int c; diff --git a/clang-tools-extra/clangd/unittests/FileIndexTests.cpp b/clang-tools-extra/clangd/unittests/FileIndexTests.cpp --- a/clang-tools-extra/clangd/unittests/FileIndexTests.cpp +++ b/clang-tools-extra/clangd/unittests/FileIndexTests.cpp @@ -249,7 +249,7 @@ } TEST(FileIndexTest, TemplateParamsInLabel) { - auto Source = R"cpp( + const auto *Source = R"cpp( template class vector { }; diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -2547,7 +2547,7 @@ TestTU TU = TestTU::withCode(T.code()); auto AST = TU.build(); - for (auto Comment : {"doc1", "doc2", "doc3"}) { + for (const auto *Comment : {"doc1", "doc2", "doc3"}) { for (const auto &P : T.points(Comment)) { auto H = getHover(AST, P, format::getLLVMStyle(), nullptr); ASSERT_TRUE(H); diff --git a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp --- a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp +++ b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp @@ -132,7 +132,7 @@ private: void reportDiagnostics(PathRef File, llvm::ArrayRef Diags, PublishFn Publish) { - auto D = Context::current().get(DiagsCallbackKey); + const auto *D = Context::current().get(DiagsCallbackKey); if (!D) return; Publish([&]() { @@ -671,11 +671,11 @@ FS.Files[Header] = "void foo()"; FS.Timestamps[Header] = time_t(0); - auto WithPreamble = R"cpp( + const auto *WithPreamble = R"cpp( #include "foo.h" int main() {} )cpp"; - auto WithEmptyPreamble = R"cpp(int main() {})cpp"; + const auto *WithEmptyPreamble = R"cpp(int main() {})cpp"; S.update(Foo, getInputs(Foo, WithPreamble), WantDiagnostics::Auto); S.runWithPreamble( "getNonEmptyPreamble", Foo, TUScheduler::Stale, @@ -748,7 +748,7 @@ // the same time. All reads should get the same non-null preamble. TUScheduler S(CDB, optsForTest()); auto Foo = testPath("foo.cpp"); - auto NonEmptyPreamble = R"cpp( + const auto *NonEmptyPreamble = R"cpp( #define FOO 1 #define BAR 2 @@ -844,7 +844,7 @@ auto HeaderA = testPath("a/foo.h"); auto HeaderB = testPath("b/foo.h"); - auto SourceContents = R"cpp( + const auto *SourceContents = R"cpp( #include "foo.h" int c = b; )cpp"; diff --git a/clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp b/clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp --- a/clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp +++ b/clang-tools-extra/clangd/unittests/tweaks/DefineInlineTests.cpp @@ -192,7 +192,7 @@ } TEST_F(DefineInlineTest, TransformNestedNamespaces) { - auto Test = R"cpp( + const auto *Test = R"cpp( namespace a { void bar(); namespace b { @@ -220,7 +220,7 @@ b::c::aux(); a::b::c::aux(); })cpp"; - auto Expected = R"cpp( + const auto *Expected = R"cpp( namespace a { void bar(); namespace b { @@ -252,7 +252,7 @@ } TEST_F(DefineInlineTest, TransformUsings) { - auto Test = R"cpp( + const auto *Test = R"cpp( namespace a { namespace b { namespace c { void aux(); } } } void foo(); @@ -263,7 +263,7 @@ using c::aux; namespace d = c; })cpp"; - auto Expected = R"cpp( + const auto *Expected = R"cpp( namespace a { namespace b { namespace c { void aux(); } } } void foo(){ @@ -278,7 +278,7 @@ } TEST_F(DefineInlineTest, TransformDecls) { - auto Test = R"cpp( + const auto *Test = R"cpp( void foo(); void f^oo() { class Foo { @@ -293,7 +293,7 @@ enum class EnClass { Zero, One }; EnClass y = EnClass::Zero; })cpp"; - auto Expected = R"cpp( + const auto *Expected = R"cpp( void foo(){ class Foo { public: @@ -312,7 +312,7 @@ } TEST_F(DefineInlineTest, TransformTemplDecls) { - auto Test = R"cpp( + const auto *Test = R"cpp( namespace a { template class Bar { public: @@ -329,7 +329,7 @@ bar>.bar(); aux>(); })cpp"; - auto Expected = R"cpp( + const auto *Expected = R"cpp( namespace a { template class Bar { public: @@ -350,7 +350,7 @@ } TEST_F(DefineInlineTest, TransformMembers) { - auto Test = R"cpp( + const auto *Test = R"cpp( class Foo { void foo(); }; @@ -358,7 +358,7 @@ void Foo::f^oo() { return; })cpp"; - auto Expected = R"cpp( + const auto *Expected = R"cpp( class Foo { void foo(){ return; @@ -395,7 +395,7 @@ } TEST_F(DefineInlineTest, TransformDependentTypes) { - auto Test = R"cpp( + const auto *Test = R"cpp( namespace a { template class Bar {}; } @@ -409,7 +409,7 @@ Bar B; Bar> q; })cpp"; - auto Expected = R"cpp( + const auto *Expected = R"cpp( namespace a { template class Bar {}; } @@ -511,7 +511,7 @@ } TEST_F(DefineInlineTest, TransformTypeLocs) { - auto Test = R"cpp( + const auto *Test = R"cpp( namespace a { template class Bar { public: @@ -528,7 +528,7 @@ Foo foo; a::Bar>::Baz> q; })cpp"; - auto Expected = R"cpp( + const auto *Expected = R"cpp( namespace a { template class Bar { public: @@ -549,7 +549,7 @@ } TEST_F(DefineInlineTest, TransformDeclRefs) { - auto Test = R"cpp( + const auto *Test = R"cpp( namespace a { template class Bar { public: @@ -575,7 +575,7 @@ bar(); a::test(); })cpp"; - auto Expected = R"cpp( + const auto *Expected = R"cpp( namespace a { template class Bar { public: @@ -605,12 +605,12 @@ } TEST_F(DefineInlineTest, StaticMembers) { - auto Test = R"cpp( + const auto *Test = R"cpp( namespace ns { class X { static void foo(); void bar(); }; } void ns::X::b^ar() { foo(); })cpp"; - auto Expected = R"cpp( + const auto *Expected = R"cpp( namespace ns { class X { static void foo(); void bar(){ foo(); } }; } @@ -654,7 +654,7 @@ } TEST_F(DefineInlineTest, TransformTemplParamNames) { - auto Test = R"cpp( + const auto *Test = R"cpp( struct Foo { struct Bar { template class V, template class W, int X, int Y> void Foo::Bar::f^oo(U, W, int Q) {})cpp"; - auto Expected = R"cpp( + const auto *Expected = R"cpp( struct Foo { struct Bar { template