[PATCH] D49439: [Sema] Fix a crash while converting constructors to deduction guides

Erik Pilkington via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 17 11:38:51 PDT 2018


erik.pilkington created this revision.
erik.pilkington added a reviewer: rsmith.
Herald added a reviewer: javed.absar.
Herald added subscribers: dexonsmith, kristof.beyls.

The problem was with constructors that have parameters that refer to previous ones, such as `D` below:

  template <size_t> struct A {};
  template <class T> struct D {
    D(T t, A<sizeof(t)>);
  };
  int main() { D d(0, A<4>()); }

We were canonicalizing the type of A<sizeof(t)> to refer to the `t` in the constructor as opposed to the new one in the deduction guide. This is because ParmVarDecls are profiled based on their type and offset, so the two ParmVarDecls profiled to the same ID, despite them belonging to distinct functions. The fix for this here is to add a bit to ParmVarDecl, IsParamOfDeductionGuide, that tracks if this ParmVarDecl is "spliced" from another function. This makes references to the new ParmVarDecl not canonicalize to the previous ParmVarDecl.

This patch also fixes a closely related bug where newly created ParmVarDecls were not being added to the CurrentInstantiationScope, leading to an assert when we try to find it later.

rdar://41330135

Thanks for taking a look!
Erik


Repository:
  rC Clang

https://reviews.llvm.org/D49439

Files:
  clang/include/clang/AST/Decl.h
  clang/lib/AST/StmtProfile.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49439.155928.patch
Type: text/x-patch
Size: 3914 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180717/55193e71/attachment.bin>


More information about the cfe-commits mailing list