]> granicus.if.org Git - clang/commitdiff
[AST] Perform additional canonicalization for DependentSizedArrayType
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 24 Jul 2015 05:54:19 +0000 (05:54 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 24 Jul 2015 05:54:19 +0000 (05:54 +0000)
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

lib/AST/ASTContext.cpp
test/SemaCXX/alias-template.cpp

index 61bd1077941fdb151f69e3aa393fab5573066ece..ba4bcbc488c9f515a926675b3cc403467b0d0ea1 100644 (file)
@@ -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
index d5eb27a66132dcda605b54039035a08c2528e5ec..bcfe428c69dd8d2f0c814d7faf43af1d0412fce7 100644 (file)
@@ -168,3 +168,14 @@ namespace SFINAE {
   fail1<int> f1; // expected-note {{here}}
   fail2<E> f2; // expected-note {{here}}
 }
+
+namespace PR24212 {
+struct X {};
+template <int I>
+struct S {
+  template <int J>
+  using T = X[J];
+  using U = T<I>;
+};
+static_assert(__is_same(S<3>::U, X[2]), ""); // expected-error {{static_assert failed}}
+}