Skip to content

Commit

Permalink
[clangd][c++20]Check for correct auto location in DeducedTypeVisitor
Browse files Browse the repository at this point in the history
In case of a constrained auto the correct location has to chosen.

Differential Revision: https://reviews.llvm.org/D154623
  • Loading branch information
jensmassberg committed Jul 10, 2023
1 parent 43cfc78 commit 7ec9e20
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion clang-tools-extra/clangd/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
12 changes: 11 additions & 1 deletion clang-tools-extra/clangd/unittests/HoverTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 different depending on the target triplet, we chose a
// fixed one to make sure tests passes on different platform.
TU.ExtraArgs.push_back("--target=x86_64-pc-linux-gnu");
Expand Down

0 comments on commit 7ec9e20

Please sign in to comment.