[clang-tools-extra] 7ec9e20 - [clangd][c++20]Check for correct auto location in DeducedTypeVisitor
Jens Massberg via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 10 02:34:11 PDT 2023
Author: Jens Massberg
Date: 2023-07-10T11:33:42+02:00
New Revision: 7ec9e2048024daa2fbd02a1b64f62194326abbbd
URL: https://github.com/llvm/llvm-project/commit/7ec9e2048024daa2fbd02a1b64f62194326abbbd
DIFF: https://github.com/llvm/llvm-project/commit/7ec9e2048024daa2fbd02a1b64f62194326abbbd.diff
LOG: [clangd][c++20]Check for correct auto location in DeducedTypeVisitor
In case of a constrained auto the correct location has to chosen.
Differential Revision: https://reviews.llvm.org/D154623
Added:
Modified:
clang-tools-extra/clangd/AST.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/AST.cpp b/clang-tools-extra/clangd/AST.cpp
index 17c4dbf6dbe70d..5b81ec213ff984 100644
--- a/clang-tools-extra/clangd/AST.cpp
+++ b/clang-tools-extra/clangd/AST.cpp
@@ -482,7 +482,11 @@ class DeducedTypeVisitor : public RecursiveASTVisitor<DeducedTypeVisitor> {
//- auto* i = &a;
bool VisitDeclaratorDecl(DeclaratorDecl *D) {
if (!D->getTypeSourceInfo() ||
- D->getTypeSourceInfo()->getTypeLoc().getBeginLoc() != SearchedLocation)
+ !D->getTypeSourceInfo()->getTypeLoc().getContainedAutoTypeLoc() ||
+ D->getTypeSourceInfo()
+ ->getTypeLoc()
+ .getContainedAutoTypeLoc()
+ .getNameLoc() != SearchedLocation)
return true;
if (auto *AT = D->getType()->getContainedAutoType()) {
diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 0f45e7851bc87e..91060a517de530 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -477,6 +477,16 @@ class Foo final {})cpp";
HI.Kind = index::SymbolKind::TypeAlias;
HI.Definition = "/* not deduced */";
}},
+ // constrained auto
+ {R"cpp(
+ template <class T> concept F = true;
+ F [[au^to]] x = 1;
+ )cpp",
+ [](HoverInfo &HI) {
+ HI.Name = "auto";
+ HI.Kind = index::SymbolKind::TypeAlias;
+ HI.Definition = "int";
+ }},
// auto on lambda
{R"cpp(
void foo() {
@@ -1314,7 +1324,7 @@ class Foo final {})cpp";
Annotations T(Case.Code);
TestTU TU = TestTU::withCode(T.code());
- TU.ExtraArgs.push_back("-std=c++17");
+ TU.ExtraArgs.push_back("-std=c++20");
// Types might be
diff erent depending on the target triplet, we chose a
// fixed one to make sure tests passes on
diff erent platform.
TU.ExtraArgs.push_back("--target=x86_64-pc-linux-gnu");
More information about the cfe-commits
mailing list