From: David Majnemer Date: Fri, 24 Jul 2015 05:54:19 +0000 (+0000) Subject: [AST] Perform additional canonicalization for DependentSizedArrayType X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3e892d1a1d2a54c60f35713c6296cdf9915e1df4;p=clang [AST] Perform additional canonicalization for DependentSizedArrayType We treated DependentSizedArrayTypes with the same element type but differing size expressions as equivalently canonical. This would lead to bizarre behavior during template instantiation. This fixes PR24212. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@243093 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 61bd107794..ba4bcbc488 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -2759,9 +2759,10 @@ QualType ASTContext::getDependentSizedArrayType(QualType elementType, QualType canon = getQualifiedType(QualType(canonTy,0), canonElementType.Quals); - // If we didn't need extra canonicalization for the element type, - // then just use that as our result. - if (QualType(canonElementType.Ty, 0) == elementType) + // If we didn't need extra canonicalization for the element type or the size + // expression, then just use that as our result. + if (QualType(canonElementType.Ty, 0) == elementType && + canonTy->getSizeExpr() == numElements) return canon; // Otherwise, we need to build a type which follows the spelling diff --git a/test/SemaCXX/alias-template.cpp b/test/SemaCXX/alias-template.cpp index d5eb27a661..bcfe428c69 100644 --- a/test/SemaCXX/alias-template.cpp +++ b/test/SemaCXX/alias-template.cpp @@ -168,3 +168,14 @@ namespace SFINAE { fail1 f1; // expected-note {{here}} fail2 f2; // expected-note {{here}} } + +namespace PR24212 { +struct X {}; +template +struct S { + template + using T = X[J]; + using U = T; +}; +static_assert(__is_same(S<3>::U, X[2]), ""); // expected-error {{static_assert failed}} +}