[clang] [libclang] Add functions to query template parameters and fix parameter pack handling (PR #183504)

via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 2 05:20:58 PST 2026


================
@@ -3267,7 +3267,29 @@ CINDEX_LINKAGE CXType clang_Cursor_getTemplateArgumentType(CXCursor C,
                                                            unsigned I);
 
 /**
- * Retrieve the value of an Integral TemplateArgument (of a function
+ * Retrieve the type of an Integral TemplateArgument at a given index.
+ *
+ * For example, for:
+ *   template <typename T, int N>
+ *   void foo() {}
+ *
+ *   template <>
+ *   void foo<float, 42>();
+ *
+ * If called with I = 1, the type "int" will be returned (the type of the
+ * integral argument 42). An invalid type is returned if the argument at
+ * index I is not integral, or if the index is out of range.
+ *
+ * \param C a cursor representing a template specialization.
+ * \param I the zero-based index of the template argument.
+ *
+ * \returns the type of the integral template argument, or an invalid type.
+ */
+CINDEX_LINKAGE CXType clang_Cursor_getTemplateArgumentIntegralType(CXCursor C,
----------------
fscheidl wrote:

Thinking about it again, I'd prefer `clang_Cursor_getNonTypeTemplateArgumentType` after all. Extending `clang_Cursor_getTemplateArgumentType` would conflate two different things: returning the type that **is** the argument vs. the type **of** the argument's value. It would also silently break existing uses where `getTemplateArgumentType(I).kind != CXType_Invalid` is used detect whether an argument is a type argument. 

https://github.com/llvm/llvm-project/pull/183504


More information about the cfe-commits mailing list