Index: lib/Sema/SemaTemplateInstantiate.cpp =================================================================== --- lib/Sema/SemaTemplateInstantiate.cpp +++ lib/Sema/SemaTemplateInstantiate.cpp @@ -1399,6 +1399,9 @@ QualType Replacement = Arg.getAsType(); + // Always canonicalize the replacement type. + Replacement = getSema().Context.getCanonicalType(Replacement); + // TODO: only do this uniquing once, at the start of instantiation. QualType Result = getSema().Context.getSubstTemplateTypeParmType(T, Replacement); @@ -1444,6 +1447,9 @@ Arg = getPackSubstitutedTemplateArgument(getSema(), Arg); QualType Result = Arg.getAsType(); + // Always canonicalize the replacement type. + Result = SemaRef.Context.getCanonicalType(Result); + Result = getSema().Context.getSubstTemplateTypeParmType( TL.getTypePtr()->getReplacedParameter(), Result); Index: test/SemaTemplate/crash-pr19372.cpp =================================================================== --- /dev/null +++ test/SemaTemplate/crash-pr19372.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 %s -std=c++11 -verify + +// Reduced from user code in http://llvm.org/PR19372 + +// expected-no-diagnostics + +template struct integral_constant { + static constexpr _Tp value = __v; +}; +template