[llvm-branch-commits] [clang] [clang-tools-extra] [clang][HeuristicResolver] Default argument heuristic for template parameters (PR #131074)
Nathan Ridge via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Mar 20 23:13:54 PDT 2025
================
@@ -125,6 +126,20 @@ TagDecl *HeuristicResolverImpl::resolveTypeToTagDecl(QualType QT) {
if (!T)
return nullptr;
+ // If T is the type of a template parameter, we can't get a useful TagDecl
+ // out of it. However, if the template parameter has a default argument,
+ // as a heuristic we can replace T with the default argument type.
+ if (const auto *TTPT = dyn_cast<TemplateTypeParmType>(T)) {
+ if (const auto *TTPD = TTPT->getDecl()) {
+ if (TTPD->hasDefaultArgument()) {
+ const auto &DefaultArg = TTPD->getDefaultArgument().getArgument();
+ if (DefaultArg.getKind() == TemplateArgument::Type) {
+ T = DefaultArg.getAsType().getTypePtrOrNull();
----------------
HighCommander4 wrote:
Thanks for the added testcases!
The recursive case made me realize that application of this heuristic is probably better done in `simplifyType`. I updated the patch and added the testcase.
For the template template parameter case, I agree that it would be nice to make this work as well, but I'd rather leave that to a follow-up patch.
https://github.com/llvm/llvm-project/pull/131074
More information about the llvm-branch-commits
mailing list