r243093 - [AST] Perform additional canonicalization for DependentSizedArrayType

David Majnemer david.majnemer at gmail.com
Thu Jul 23 22:54:19 PDT 2015


Author: majnemer
Date: Fri Jul 24 00:54:19 2015
New Revision: 243093

URL: http://llvm.org/viewvc/llvm-project?rev=243093&view=rev
Log:
[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.

Modified:
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/test/SemaCXX/alias-template.cpp

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=243093&r1=243092&r2=243093&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Jul 24 00:54:19 2015
@@ -2759,9 +2759,10 @@ QualType ASTContext::getDependentSizedAr
   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

Modified: cfe/trunk/test/SemaCXX/alias-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/alias-template.cpp?rev=243093&r1=243092&r2=243093&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/alias-template.cpp (original)
+++ cfe/trunk/test/SemaCXX/alias-template.cpp Fri Jul 24 00:54:19 2015
@@ -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}}
+}





More information about the cfe-commits mailing list