martong added inline comments.

================
Comment at: clang/lib/AST/ASTImporter.cpp:3269-3273
+    // Note: It is possible that T can be get as both a RecordType and a
+    // TemplateSpecializationType.
+  }
+  if (const auto *TST = T->getAs<TemplateSpecializationType>()) {
+    return llvm::count_if(TST->template_arguments(), CheckTemplateArgument);
----------------
balazske wrote:
> martong wrote:
> > Is it possible that `T` is both a `RecordType` and a 
> > `TemplateSpecializationType` at the same time? From the [[ 
> > https://clang.llvm.org/doxygen/classclang_1_1TemplateSpecializationType.html
> >  | hierarchy ]] this seems impossible (?)
> The type dump shows that a `RecordType` is contained within the 
> `TemplateSpecializationType` and it looks like that the get function handles 
> this case. When the `else` is added the check of `TemplateSpecializationType` 
> is skipped and the template argument expression `X` is not found (only 
> integer constant `1`).
> ```
> TemplateSpecializationType 0x23fd8c0 'Tmpl<X>' sugar Tmpl
> |-TemplateArgument expr
> | `-ConstantExpr 0x23fd798 'int'
> |   |-value: Int 1
> |   `-ImplicitCastExpr 0x23fd780 'int' <LValueToRValue>
> |     `-DeclRefExpr 0x23fd760 'const int' lvalue Var 0x23fd648 'X' 'const 
> int' non_odr_use_constant
> `-RecordType 0x23fd8a0 'struct Tmpl<1>'
>   `-ClassTemplateSpecialization 0x23fd7b8 'Tmpl'
> ```
Okay. I've dug deeper to understand how that is working. So, in the 
`TemplateSpecializationType` 'Tmpl<X>' is actually a "sugar" to the 
`RecordType` 'struct Tmpl<1>'. 
And `getAs<RecordType>` will return with the desugared type:
```
  // If this is a typedef for the type, strip the typedef off without
  // losing all typedef information.
  return cast<T>(getUnqualifiedDesugaredType());
``` 
Thus, to answer my own question,  it is possible that T is both a RecordType 
and a TemplateSpecializationType at the same time!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129640/new/

https://reviews.llvm.org/D129640

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to