[llvm-branch-commits] [clang] [clang-tools-extra] [clang][HeuristicResolver] Default argument heuristic for template parameters (PR #131074)
Haojian Wu via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Mar 19 04:54:08 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();
----------------
hokein wrote:
the code doesn't look safe -- `getTypePtrOrNull` could return a nullptr, then we have a null-reference on Line144. Move this new code block before line 126?
https://github.com/llvm/llvm-project/pull/131074
More information about the llvm-branch-commits
mailing list