https://github.com/Serafean updated 
https://github.com/llvm/llvm-project/pull/172472

>From 4c3d27c14d8554ab16d652c404a8b475b8a19689 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Bedn=C3=A1r?= <[email protected]>
Date: Tue, 16 Dec 2025 13:21:14 +0100
Subject: [PATCH] [clang][libclang]Check auto type for type constraints

the "auto" keyword was visited by the default visitor only, making any
type constraints unavailable through the libclang API.

Add an explicit visitor for AutoType, check for constraints, and visit
those.

Fixes issue #166580
---
 clang/docs/ReleaseNotes.rst     |  1 +
 clang/test/Index/index-auto.cpp | 18 ++++++++++++++++++
 clang/tools/libclang/CIndex.cpp | 15 ++++++++++++++-
 3 files changed, 33 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Index/index-auto.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4f732ba81d78f..6cdd888cabe12 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -382,6 +382,7 @@ clang-format
 
 libclang
 --------
+- Visit constraints of `auto` type to properly visit concept usages (#GH166580)
 
 Code Completion
 ---------------
diff --git a/clang/test/Index/index-auto.cpp b/clang/test/Index/index-auto.cpp
new file mode 100644
index 0000000000000..5e8af7287d9bb
--- /dev/null
+++ b/clang/test/Index/index-auto.cpp
@@ -0,0 +1,18 @@
+// RUN: c-index-test -test-load-source all %s -std=gnu++20 | FileCheck %s
+
+template<typename T>
+concept Decrementable = requires (T t){ --t; };
+
+auto i = 42;
+// CHECK: index-auto.cpp:[[@LINE-1]]:6: VarDecl=i:[[@LINE-1]]:6 (Definition) 
Extent=[[[@LINE-1]]:1 - [[@LINE-1]]:12]
+
+auto foo(){ return 42;}
+// CHECK: index-auto.cpp:[[@LINE-1]]:6: FunctionDecl=foo:[[@LINE-1]]:6 
(Definition) Extent=[[[@LINE-1]]:1 - [[@LINE-1]]:24]
+
+Decrementable auto j = 43;
+// CHECK: index-auto.cpp:[[@LINE-1]]:20: VarDecl=j:[[@LINE-1]]:20 (Definition) 
Extent=[[[@LINE-1]]:1 - [[@LINE-1]]:26]
+// CHECK: index-auto.cpp:[[@LINE-2]]:1: TemplateRef=Decrementable:4:9 
Extent=[[[@LINE-2]]:1 - [[@LINE-2]]:14]
+
+Decrementable auto bar() { return 43; }
+// CHECK: index-auto.cpp:[[@LINE-1]]:20: FunctionDecl=bar:[[@LINE-1]]:20 
(Definition) Extent=[[[@LINE-1]]:1 - [[@LINE-1]]:40]
+// CHECK: index-auto.cpp:[[@LINE-2]]:1: TemplateRef=Decrementable:4:9 
Extent=[[[@LINE-2]]:1 - [[@LINE-2]]:14]
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 15eec87652451..fdde7610faf35 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -1789,6 +1789,20 @@ bool CursorVisitor::VisitAdjustedTypeLoc(AdjustedTypeLoc 
TL) {
   return Visit(TL.getOriginalLoc());
 }
 
+bool CursorVisitor::VisitAutoTypeLoc(AutoTypeLoc TL) {
+
+  if (TL.isConstrained()) {
+    if (auto *CR = TL.getConceptReference()) {
+      if (CR->getNamedConcept()) {
+        return Visit(MakeCursorTemplateRef(CR->getNamedConcept(),
+                                           CR->getConceptNameLoc(), TU));
+      }
+    }
+  }
+
+  return false;
+}
+
 bool CursorVisitor::VisitDeducedTemplateSpecializationTypeLoc(
     DeducedTemplateSpecializationTypeLoc TL) {
   if (VisitTemplateName(TL.getTypePtr()->getTemplateName(),
@@ -1889,7 +1903,6 @@ DEFAULT_TYPELOC_IMPL(Enum, TagType)
 DEFAULT_TYPELOC_IMPL(SubstTemplateTypeParm, Type)
 DEFAULT_TYPELOC_IMPL(SubstTemplateTypeParmPack, Type)
 DEFAULT_TYPELOC_IMPL(SubstBuiltinTemplatePack, Type)
-DEFAULT_TYPELOC_IMPL(Auto, Type)
 DEFAULT_TYPELOC_IMPL(BitInt, Type)
 DEFAULT_TYPELOC_IMPL(DependentBitInt, Type)
 

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to