<div dir="ltr">Hi,<br><br>Considering the below code:<br>01<br>02  struct A {};<br>03  typedef A AT;<br>04<br>05  template <typename T> struct ClassT {<br>06    ClassT(AT p0, T* p1) {}<br>07  };<br>08<br>09  A a;<br>10  int x;<br>11  auto y = ClassT(a, &x);<br><br>The deduction guide's first parameter refers to a TypedefDecl that is isolated<br>from the first TypedefDecl. First declaration:<br><br>|-TypedefDecl <b>0x5555561eaec0</b> <line:3:3, col:13> col:13 referenced AT 'A'<br>| `-RecordType 0x5555561ead80 'A'<br>|   `-CXXRecord 0x5555561eacf0 'A'<br><br>Vs the function prototype of the deduction guide refers to an isolated<br>(out-of-the-redecl-chain) TypedefDecl:<br><br>FunctionProtoType 0x55555621bc80 'auto (AT, T *) -> ClassT<T>' dependent trailing_return cdecl<br>|-InjectedClassNameType 0x5555561eb220 'ClassT<T>' dependent<br>| `-CXXRecord 0x5555561eafe0 'ClassT'<br>|-TypedefType 0x55555621bb20 'AT' sugar<br>| |-Typedef <b>0x55555621bac0</b> 'AT'<br>| `-RecordType 0x5555561ead80 'struct A'<br>|   `-CXXRecord 0x5555561eacf0 'A'<br>`-PointerType 0x5555561eb410 'T *' dependent<br>  `-TemplateTypeParmType 0x5555561eafa0 'T' dependent depth 0 index 0<br>    `-TemplateTypeParm 0x5555561eaf18 'T'<br><br>So, in the translation unit, we have two distinct TypedefDecl AST nodes. The<br>first one's DeclContext is the TranslationUnidDecl, however, the second's is<br>the CXXDeductionGuideDecl.<br><br>This is strange, because when dealing with regular function template<br>instantiations, the two typedefs are the same and we have only one universal<br>TypedefDecl node in the AST.<br>01<br>02  struct A {};<br>03  typedef A AT;<br>04<br>05  template <typename T><br>06  int fun(AT p0, T* p1) {}<br>07<br>08  A a;<br>09  int x;<br>10  int y = fun(a, &x);<br><br>TypedefDecl <b>0x5555561eaf70</b> <input.cc:3:3, col:13> col:13 referenced AT 'A'<br>`-RecordType 0x5555561eae30 'A'<br>  `-CXXRecord 0x5555561eada0 'A'<br><br>FunctionProtoType 0x5555561eb240 'int (AT, T *)' dependent cdecl<br>|-BuiltinType 0x5555561ab0a0 'int'<br>|-TypedefType 0x5555561eb090 'AT' sugar<br>| |-Typedef <b>0x5555561eaf70</b> 'AT'<br>| `-RecordType 0x5555561eae30 'struct A'<br>|   `-CXXRecord 0x5555561eada0 'A'<br>`-PointerType 0x5555561eb160 'T *' dependent<br>  `-TemplateTypeParmType 0x5555561eb050 'T' dependent depth 0 index 0<br>    `-TemplateTypeParm 0x5555561eafc8 'T'<br><br>I was wondering whether this discrepancy is deliberate. IMO, the deduction<br>guide should refer to the TypedefDecl in the TranslationUnidDecl and it should<br>not create a new TypedefDecl. Can someone confirm if this is a bug or not?<br><br>Context: I am trying to fix an infinite loop in the ASTImporter that is related<br>to importing deduction guidelines.<br><br>Any insight would be really appreciated.<br><br>Thanks,<br>Gabor<br><br></div>