aaron.ballman added a comment. Mostly nits from me (FWIW, we use `auto` when the type is explicitly spelled out in the initialization and we don't usually use `else` after an unconditional `return` as a matter of coding style.) In terms of the test coverage, I would probably make a new test modeled after https://github.com/llvm/llvm-project/blob/main/clang/test/Index/cxx14-lambdas.cpp.
================ Comment at: clang/include/clang-c/Index.h:3594-3595 /** - *Returns the number of template args of a function decl representing a - * template specialization. + *Returns the number of template args of a function, struct, or class decl + *representing a template specialization. * ---------------- Since we're in the area already... ================ Comment at: clang/tools/libclang/CXCursor.cpp:1357 + CXCursorKind kind = clang_getCursorKind(C); + if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl && + kind != CXCursor_ClassDecl && ---------------- `CXCursor_StructDecl` is interesting -- does that only get used in C or will it also show up in C++? If it's C-only, we can drop that bit. ================ Comment at: clang/tools/libclang/CXCursor.cpp:1363 - const FunctionDecl *FD = - llvm::dyn_cast_or_null<clang::FunctionDecl>(getCursorDecl(C)); - if (!FD) { - return -1; - } - - const FunctionTemplateSpecializationInfo *SpecInfo = - FD->getTemplateSpecializationInfo(); - if (!SpecInfo) { + if (const FunctionDecl *FD = + llvm::dyn_cast_if_present<clang::FunctionDecl>(getCursorDecl(C))) { ---------------- ================ Comment at: clang/tools/libclang/CXCursor.cpp:1370-1379 + return SpecInfo->TemplateArguments->size(); + } else if (const ClassTemplateSpecializationDecl *SD = + llvm::dyn_cast_if_present< + clang::ClassTemplateSpecializationDecl>( + getCursorDecl(C))) { + return SD->getTemplateArgs().size(); + } else { ---------------- ================ Comment at: clang/tools/libclang/CXCursor.cpp:1403 + CXCursorKind kind = clang_getCursorKind(C); + if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl && + kind != CXCursor_ClassDecl && ---------------- Same question here about struct decl as above. ================ Comment at: clang/tools/libclang/CXCursor.cpp:1409 - const FunctionDecl *FD = - llvm::dyn_cast_or_null<clang::FunctionDecl>(getCursorDecl(C)); - if (!FD) { - return CXGetTemplateArgumentStatus_BadFunctionDeclCast; - } + if (const FunctionDecl *FD = + llvm::dyn_cast_if_present<clang::FunctionDecl>(getCursorDecl(C))) { ---------------- ================ Comment at: clang/tools/libclang/CXCursor.cpp:1423-1439 + return 0; + } else if (const ClassTemplateSpecializationDecl *SD = + llvm::dyn_cast_if_present< + clang::ClassTemplateSpecializationDecl>( + getCursorDecl(C))) { + if (I >= SD->getTemplateArgs().size()) { + printf("INVALID INDEX\n"); ---------------- Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D134416/new/ https://reviews.llvm.org/D134416 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits