From: Stephan Tolksdorf Date: Sat, 15 Mar 2014 10:23:27 +0000 (+0000) Subject: Fix PR18806: Canonicalize the replacement type when deserializing a SubstTemplateType... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3b4e983aa6800b74cabbd45cdb516a2853ed528f;p=clang Fix PR18806: Canonicalize the replacement type when deserializing a SubstTemplateTypeParmType What's going on in the test case (without the patch applied) is this: When the header is parsed, decltype(B()) is canonicalized to decltype(Y()), because that was the first parsed equivalent decltype expression. Hence, the TemplateSpecializationType for Id ends up with SubstTemplateTypeParmType(T, decltype(Y())) as the AliasedType member. When the PCH file is included and the AST reader reads Id, it sees decltype(B()) before decltype(Y()). So, this time decltype(B()) ends up being the canonical type for both decltypes, which leads to an assert violation when the reader calls getSubstTemplateTypeParmType with the non-canonical decltype(Y()) as the replacement type. Reviewers: rsmith Reviewed By: rsmith CC: cfe-commits, aemerson Differential Revision: http://llvm-reviews.chandlerc.com/D3073 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204005 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 7781a7d1b0..a0ee3d37c5 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -5203,9 +5203,9 @@ QualType ASTReader::readTypeRecord(unsigned Index) { unsigned Idx = 0; QualType Parm = readType(*Loc.F, Record, Idx); QualType Replacement = readType(*Loc.F, Record, Idx); - return - Context.getSubstTemplateTypeParmType(cast(Parm), - Replacement); + return Context.getSubstTemplateTypeParmType( + cast(Parm), + Context.getCanonicalType(Replacement)); } case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { diff --git a/test/PCH/pr18806.cpp b/test/PCH/pr18806.cpp new file mode 100644 index 0000000000..c28320db95 --- /dev/null +++ b/test/PCH/pr18806.cpp @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -std=c++11 -emit-pch -o %t %s +// RUN: %clang_cc1 -std=c++11 -include-pch %t -verify %s + +// expected-no-diagnostics + +// Before the patch, this test triggered an assert violation in +// ASTContext::getSubstTemplateTypeParmType. + +#ifndef HEADER_INCLUDED +#define HEADER_INCLUDED + +template +using Id = T; + +template +struct Class1 { + template + struct Nested1; +}; + +template +struct Class2 { + template > + struct Nested2; +}; + +#else + +Class2 test; + +#endif